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, val);
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, val);
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, val);
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, val);
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, val);
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, val);
116 * Creates a copy of the InMemorySigner
118 public InMemorySigner clone() {
119 long ret = bindings.InMemorySigner_clone(this.ptr);
120 if (ret < 1024) { return null; }
121 InMemorySigner ret_hu_conv = new InMemorySigner(null, ret);
122 ret_hu_conv.ptrs_to.add(this);
127 * Create a new InMemorySigner
129 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) {
130 long ret = bindings.InMemorySigner_new(funding_key, revocation_base_key, payment_key, delayed_payment_base_key, htlc_base_key, commitment_seed, channel_value_satoshis, channel_keys_id);
131 if (ret < 1024) { return null; }
132 InMemorySigner ret_hu_conv = new InMemorySigner(null, ret);
133 ret_hu_conv.ptrs_to.add(ret_hu_conv);
138 * Counterparty pubkeys.
139 * Will panic if ready_channel wasn't called.
141 public ChannelPublicKeys counterparty_pubkeys() {
142 long ret = bindings.InMemorySigner_counterparty_pubkeys(this.ptr);
143 if (ret < 1024) { return null; }
144 ChannelPublicKeys ret_hu_conv = new ChannelPublicKeys(null, ret);
145 ret_hu_conv.ptrs_to.add(this);
150 * The contest_delay value specified by our counterparty and applied on holder-broadcastable
151 * transactions, ie the amount of time that we have to wait to recover our funds if we
152 * broadcast a transaction.
153 * Will panic if ready_channel wasn't called.
155 public short counterparty_selected_contest_delay() {
156 short ret = bindings.InMemorySigner_counterparty_selected_contest_delay(this.ptr);
161 * The contest_delay value specified by us and applied on transactions broadcastable
162 * by our counterparty, ie the amount of time that they have to wait to recover their funds
163 * if they broadcast a transaction.
164 * Will panic if ready_channel wasn't called.
166 public short holder_selected_contest_delay() {
167 short ret = bindings.InMemorySigner_holder_selected_contest_delay(this.ptr);
172 * Whether the holder is the initiator
173 * Will panic if ready_channel wasn't called.
175 public boolean is_outbound() {
176 boolean ret = bindings.InMemorySigner_is_outbound(this.ptr);
182 * Will panic if ready_channel wasn't called.
184 public OutPoint funding_outpoint() {
185 long ret = bindings.InMemorySigner_funding_outpoint(this.ptr);
186 if (ret < 1024) { return null; }
187 OutPoint ret_hu_conv = new OutPoint(null, ret);
188 ret_hu_conv.ptrs_to.add(this);
193 * Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
194 * building transactions.
196 * Will panic if ready_channel wasn't called.
198 public ChannelTransactionParameters get_channel_parameters() {
199 long ret = bindings.InMemorySigner_get_channel_parameters(this.ptr);
200 if (ret < 1024) { return null; }
201 ChannelTransactionParameters ret_hu_conv = new ChannelTransactionParameters(null, ret);
202 ret_hu_conv.ptrs_to.add(this);
207 * Sign the single input of spend_tx at index `input_idx` which spends the output
208 * described by descriptor, returning the witness stack for the input.
210 * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
211 * or is not spending the outpoint described by `descriptor.outpoint`.
213 public Result_CVec_CVec_u8ZZNoneZ sign_counterparty_payment_input(byte[] spend_tx, long input_idx, StaticPaymentOutputDescriptor descriptor) {
214 long ret = bindings.InMemorySigner_sign_counterparty_payment_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
215 if (ret < 1024) { return null; }
216 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
217 this.ptrs_to.add(descriptor);
222 * Sign the single input of spend_tx at index `input_idx` which spends the output
223 * described by descriptor, returning the witness stack for the input.
225 * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
226 * is not spending the outpoint described by `descriptor.outpoint`, or does not have a
227 * sequence set to `descriptor.to_self_delay`.
229 public Result_CVec_CVec_u8ZZNoneZ sign_dynamic_p2wsh_input(byte[] spend_tx, long input_idx, DelayedPaymentOutputDescriptor descriptor) {
230 long ret = bindings.InMemorySigner_sign_dynamic_p2wsh_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
231 if (ret < 1024) { return null; }
232 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
233 this.ptrs_to.add(descriptor);
238 * Constructs a new BaseSign which calls the relevant methods on this_arg.
239 * This copies the `inner` pointer in this_arg and thus the returned BaseSign must be freed before this_arg is
241 public BaseSign as_BaseSign() {
242 long ret = bindings.InMemorySigner_as_BaseSign(this.ptr);
243 if (ret < 1024) { return null; }
244 BaseSign ret_hu_conv = new BaseSign(null, ret);
245 ret_hu_conv.ptrs_to.add(this);
250 * Constructs a new Sign which calls the relevant methods on this_arg.
251 * This copies the `inner` pointer in this_arg and thus the returned Sign must be freed before this_arg is
253 public Sign as_Sign() {
254 long ret = bindings.InMemorySigner_as_Sign(this.ptr);
255 if (ret < 1024) { return null; }
256 Sign ret_hu_conv = new Sign(null, ret);
257 ret_hu_conv.ptrs_to.add(this);
262 * Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
264 public byte[] write() {
265 byte[] ret = bindings.InMemorySigner_write(this.ptr);
270 * Read a InMemorySigner from a byte array, created by InMemorySigner_write
272 public static Result_InMemorySignerDecodeErrorZ read(byte[] ser) {
273 long ret = bindings.InMemorySigner_read(ser);
274 if (ret < 1024) { return null; }
275 Result_InMemorySignerDecodeErrorZ ret_hu_conv = Result_InMemorySignerDecodeErrorZ.constr_from_ptr(ret);