1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
10 * A simple implementation of Sign that just keeps the private keys in memory.
12 * This implementation performs no policy checks and is insufficient by itself as
13 * a secure external signer.
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class InMemorySigner extends CommonBase {
17 InMemorySigner(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.InMemorySigner_free(ptr); }
25 * Private key of anchor tx
27 public byte[] get_funding_key() {
28 byte[] ret = bindings.InMemorySigner_get_funding_key(this.ptr);
33 * Private key of anchor tx
35 public void set_funding_key(byte[] val) {
36 bindings.InMemorySigner_set_funding_key(this.ptr, val);
40 * Holder secret key for blinded revocation pubkey
42 public byte[] get_revocation_base_key() {
43 byte[] ret = bindings.InMemorySigner_get_revocation_base_key(this.ptr);
48 * Holder secret key for blinded revocation pubkey
50 public void set_revocation_base_key(byte[] val) {
51 bindings.InMemorySigner_set_revocation_base_key(this.ptr, val);
55 * Holder secret key used for our balance in counterparty-broadcasted commitment transactions
57 public byte[] get_payment_key() {
58 byte[] ret = bindings.InMemorySigner_get_payment_key(this.ptr);
63 * Holder secret key used for our balance in counterparty-broadcasted commitment transactions
65 public void set_payment_key(byte[] val) {
66 bindings.InMemorySigner_set_payment_key(this.ptr, val);
70 * Holder secret key used in HTLC tx
72 public byte[] get_delayed_payment_base_key() {
73 byte[] ret = bindings.InMemorySigner_get_delayed_payment_base_key(this.ptr);
78 * Holder secret key used in HTLC tx
80 public void set_delayed_payment_base_key(byte[] val) {
81 bindings.InMemorySigner_set_delayed_payment_base_key(this.ptr, val);
85 * Holder htlc secret key used in commitment tx htlc outputs
87 public byte[] get_htlc_base_key() {
88 byte[] ret = bindings.InMemorySigner_get_htlc_base_key(this.ptr);
93 * Holder htlc secret key used in commitment tx htlc outputs
95 public void set_htlc_base_key(byte[] val) {
96 bindings.InMemorySigner_set_htlc_base_key(this.ptr, val);
102 public byte[] get_commitment_seed() {
103 byte[] ret = bindings.InMemorySigner_get_commitment_seed(this.ptr);
110 public void set_commitment_seed(byte[] val) {
111 bindings.InMemorySigner_set_commitment_seed(this.ptr, val);
115 * Creates a copy of the InMemorySigner
117 public InMemorySigner clone() {
118 long ret = bindings.InMemorySigner_clone(this.ptr);
119 if (ret < 1024) { return null; }
120 InMemorySigner ret_hu_conv = new InMemorySigner(null, ret);
121 ret_hu_conv.ptrs_to.add(this);
126 * Create a new InMemorySigner
128 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) {
129 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);
130 if (ret < 1024) { return null; }
131 InMemorySigner ret_hu_conv = new InMemorySigner(null, ret);
132 ret_hu_conv.ptrs_to.add(ret_hu_conv);
137 * Counterparty pubkeys.
138 * Will panic if ready_channel wasn't called.
140 public ChannelPublicKeys counterparty_pubkeys() {
141 long ret = bindings.InMemorySigner_counterparty_pubkeys(this.ptr);
142 if (ret < 1024) { return null; }
143 ChannelPublicKeys ret_hu_conv = new ChannelPublicKeys(null, ret);
144 ret_hu_conv.ptrs_to.add(this);
149 * The contest_delay value specified by our counterparty and applied on holder-broadcastable
150 * transactions, ie the amount of time that we have to wait to recover our funds if we
151 * broadcast a transaction.
152 * Will panic if ready_channel wasn't called.
154 public short counterparty_selected_contest_delay() {
155 short ret = bindings.InMemorySigner_counterparty_selected_contest_delay(this.ptr);
160 * The contest_delay value specified by us and applied on transactions broadcastable
161 * by our counterparty, ie the amount of time that they have to wait to recover their funds
162 * if they broadcast a transaction.
163 * Will panic if ready_channel wasn't called.
165 public short holder_selected_contest_delay() {
166 short ret = bindings.InMemorySigner_holder_selected_contest_delay(this.ptr);
171 * Whether the holder is the initiator
172 * Will panic if ready_channel wasn't called.
174 public boolean is_outbound() {
175 boolean ret = bindings.InMemorySigner_is_outbound(this.ptr);
181 * Will panic if ready_channel wasn't called.
183 public OutPoint funding_outpoint() {
184 long ret = bindings.InMemorySigner_funding_outpoint(this.ptr);
185 if (ret < 1024) { return null; }
186 OutPoint ret_hu_conv = new OutPoint(null, ret);
187 ret_hu_conv.ptrs_to.add(this);
192 * Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
193 * building transactions.
195 * Will panic if ready_channel wasn't called.
197 public ChannelTransactionParameters get_channel_parameters() {
198 long ret = bindings.InMemorySigner_get_channel_parameters(this.ptr);
199 if (ret < 1024) { return null; }
200 ChannelTransactionParameters ret_hu_conv = new ChannelTransactionParameters(null, ret);
201 ret_hu_conv.ptrs_to.add(this);
206 * Sign the single input of spend_tx at index `input_idx` which spends the output
207 * described by descriptor, returning the witness stack for the input.
209 * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
210 * or is not spending the outpoint described by `descriptor.outpoint`.
212 public Result_CVec_CVec_u8ZZNoneZ sign_counterparty_payment_input(byte[] spend_tx, long input_idx, StaticPaymentOutputDescriptor descriptor) {
213 long ret = bindings.InMemorySigner_sign_counterparty_payment_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
214 if (ret < 1024) { return null; }
215 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
216 this.ptrs_to.add(descriptor);
221 * Sign the single input of spend_tx at index `input_idx` which spends the output
222 * described by descriptor, returning the witness stack for the input.
224 * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
225 * is not spending the outpoint described by `descriptor.outpoint`, or does not have a
226 * sequence set to `descriptor.to_self_delay`.
228 public Result_CVec_CVec_u8ZZNoneZ sign_dynamic_p2wsh_input(byte[] spend_tx, long input_idx, DelayedPaymentOutputDescriptor descriptor) {
229 long ret = bindings.InMemorySigner_sign_dynamic_p2wsh_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
230 if (ret < 1024) { return null; }
231 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
232 this.ptrs_to.add(descriptor);
237 * Constructs a new BaseSign which calls the relevant methods on this_arg.
238 * This copies the `inner` pointer in this_arg and thus the returned BaseSign must be freed before this_arg is
240 public BaseSign as_BaseSign() {
241 long ret = bindings.InMemorySigner_as_BaseSign(this.ptr);
242 if (ret < 1024) { return null; }
243 BaseSign ret_hu_conv = new BaseSign(null, ret);
244 ret_hu_conv.ptrs_to.add(this);
249 * Constructs a new Sign which calls the relevant methods on this_arg.
250 * This copies the `inner` pointer in this_arg and thus the returned Sign must be freed before this_arg is
252 public Sign as_Sign() {
253 long ret = bindings.InMemorySigner_as_Sign(this.ptr);
254 if (ret < 1024) { return null; }
255 Sign ret_hu_conv = new Sign(null, ret);
256 ret_hu_conv.ptrs_to.add(this);
261 * Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
263 public byte[] write() {
264 byte[] ret = bindings.InMemorySigner_write(this.ptr);
269 * Read a InMemorySigner from a byte array, created by InMemorySigner_write
271 public static Result_InMemorySignerDecodeErrorZ read(byte[] ser) {
272 long ret = bindings.InMemorySigner_read(ser);
273 if (ret < 1024) { return null; }
274 Result_InMemorySignerDecodeErrorZ ret_hu_conv = Result_InMemorySignerDecodeErrorZ.constr_from_ptr(ret);