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 InMemorySigner ret_hu_conv = new InMemorySigner(null, ret);
120 ret_hu_conv.ptrs_to.add(this);
125 * Create a new InMemorySigner
127 public static InMemorySigner constructor_new(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) {
128 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);
129 InMemorySigner ret_hu_conv = new InMemorySigner(null, ret);
130 ret_hu_conv.ptrs_to.add(ret_hu_conv);
135 * Counterparty pubkeys.
136 * Will panic if ready_channel wasn't called.
138 public ChannelPublicKeys counterparty_pubkeys() {
139 long ret = bindings.InMemorySigner_counterparty_pubkeys(this.ptr);
140 ChannelPublicKeys ret_hu_conv = new ChannelPublicKeys(null, ret);
141 ret_hu_conv.ptrs_to.add(this);
146 * The contest_delay value specified by our counterparty and applied on holder-broadcastable
147 * transactions, ie the amount of time that we have to wait to recover our funds if we
148 * broadcast a transaction.
149 * Will panic if ready_channel wasn't called.
151 public short counterparty_selected_contest_delay() {
152 short ret = bindings.InMemorySigner_counterparty_selected_contest_delay(this.ptr);
157 * The contest_delay value specified by us and applied on transactions broadcastable
158 * by our counterparty, ie the amount of time that they have to wait to recover their funds
159 * if they broadcast a transaction.
160 * Will panic if ready_channel wasn't called.
162 public short holder_selected_contest_delay() {
163 short ret = bindings.InMemorySigner_holder_selected_contest_delay(this.ptr);
168 * Whether the holder is the initiator
169 * Will panic if ready_channel wasn't called.
171 public boolean is_outbound() {
172 boolean ret = bindings.InMemorySigner_is_outbound(this.ptr);
178 * Will panic if ready_channel wasn't called.
180 public OutPoint funding_outpoint() {
181 long ret = bindings.InMemorySigner_funding_outpoint(this.ptr);
182 OutPoint ret_hu_conv = new OutPoint(null, ret);
183 ret_hu_conv.ptrs_to.add(this);
188 * Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
189 * building transactions.
191 * Will panic if ready_channel wasn't called.
193 public ChannelTransactionParameters get_channel_parameters() {
194 long ret = bindings.InMemorySigner_get_channel_parameters(this.ptr);
195 ChannelTransactionParameters ret_hu_conv = new ChannelTransactionParameters(null, ret);
196 ret_hu_conv.ptrs_to.add(this);
201 * Sign the single input of spend_tx at index `input_idx` which spends the output
202 * described by descriptor, returning the witness stack for the input.
204 * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
205 * or is not spending the outpoint described by `descriptor.outpoint`.
207 public Result_CVec_CVec_u8ZZNoneZ sign_counterparty_payment_input(byte[] spend_tx, long input_idx, StaticPaymentOutputDescriptor descriptor) {
208 long ret = bindings.InMemorySigner_sign_counterparty_payment_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
209 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
210 this.ptrs_to.add(descriptor);
215 * Sign the single input of spend_tx at index `input_idx` which spends the output
216 * described by descriptor, returning the witness stack for the input.
218 * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
219 * is not spending the outpoint described by `descriptor.outpoint`, or does not have a
220 * sequence set to `descriptor.to_self_delay`.
222 public Result_CVec_CVec_u8ZZNoneZ sign_dynamic_p2wsh_input(byte[] spend_tx, long input_idx, DelayedPaymentOutputDescriptor descriptor) {
223 long ret = bindings.InMemorySigner_sign_dynamic_p2wsh_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
224 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
225 this.ptrs_to.add(descriptor);
230 * Constructs a new Sign which calls the relevant methods on this_arg.
231 * This copies the `inner` pointer in this_arg and thus the returned Sign must be freed before this_arg is
233 public Sign as_Sign() {
234 long ret = bindings.InMemorySigner_as_Sign(this.ptr);
235 Sign ret_hu_conv = new Sign(null, ret);
236 ret_hu_conv.ptrs_to.add(this);
241 * Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
243 public byte[] write() {
244 byte[] ret = bindings.InMemorySigner_write(this.ptr);
249 * Read a InMemorySigner from a byte array, created by InMemorySigner_write
251 public static Result_InMemorySignerDecodeErrorZ constructor_read(byte[] ser) {
252 long ret = bindings.InMemorySigner_read(ser);
253 Result_InMemorySignerDecodeErrorZ ret_hu_conv = Result_InMemorySignerDecodeErrorZ.constr_from_ptr(ret);