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 * The set of public keys which are used in the creation of one commitment transaction.
12 * These are derived from the channel base keys and per-commitment data.
14 * A broadcaster key is provided from potential broadcaster of the computed transaction.
15 * A countersignatory key is coming from a protocol participant unable to broadcast the
18 * These keys are assumed to be good, either because the code derived them from
19 * channel basepoints via the new function, or they were obtained via
20 * CommitmentTransaction.trust().keys() because we trusted the source of the
21 * pre-calculated keys.
23 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
24 public class TxCreationKeys extends CommonBase {
25 TxCreationKeys(Object _dummy, long ptr) { super(ptr); }
26 @Override @SuppressWarnings("deprecation")
27 protected void finalize() throws Throwable {
29 if (ptr != 0) { bindings.TxCreationKeys_free(ptr); }
33 * The broadcaster's per-commitment public key which was used to derive the other keys.
35 public byte[] get_per_commitment_point() {
36 byte[] ret = bindings.TxCreationKeys_get_per_commitment_point(this.ptr);
41 * The broadcaster's per-commitment public key which was used to derive the other keys.
43 public void set_per_commitment_point(byte[] val) {
44 bindings.TxCreationKeys_set_per_commitment_point(this.ptr, val);
48 * The revocation key which is used to allow the broadcaster of the commitment
49 * transaction to provide their counterparty the ability to punish them if they broadcast
52 public byte[] get_revocation_key() {
53 byte[] ret = bindings.TxCreationKeys_get_revocation_key(this.ptr);
58 * The revocation key which is used to allow the broadcaster of the commitment
59 * transaction to provide their counterparty the ability to punish them if they broadcast
62 public void set_revocation_key(byte[] val) {
63 bindings.TxCreationKeys_set_revocation_key(this.ptr, val);
67 * Broadcaster's HTLC Key
69 public byte[] get_broadcaster_htlc_key() {
70 byte[] ret = bindings.TxCreationKeys_get_broadcaster_htlc_key(this.ptr);
75 * Broadcaster's HTLC Key
77 public void set_broadcaster_htlc_key(byte[] val) {
78 bindings.TxCreationKeys_set_broadcaster_htlc_key(this.ptr, val);
82 * Countersignatory's HTLC Key
84 public byte[] get_countersignatory_htlc_key() {
85 byte[] ret = bindings.TxCreationKeys_get_countersignatory_htlc_key(this.ptr);
90 * Countersignatory's HTLC Key
92 public void set_countersignatory_htlc_key(byte[] val) {
93 bindings.TxCreationKeys_set_countersignatory_htlc_key(this.ptr, val);
97 * Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
99 public byte[] get_broadcaster_delayed_payment_key() {
100 byte[] ret = bindings.TxCreationKeys_get_broadcaster_delayed_payment_key(this.ptr);
105 * Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
107 public void set_broadcaster_delayed_payment_key(byte[] val) {
108 bindings.TxCreationKeys_set_broadcaster_delayed_payment_key(this.ptr, val);
112 * Constructs a new TxCreationKeys given each field
114 public static TxCreationKeys of(byte[] per_commitment_point_arg, byte[] revocation_key_arg, byte[] broadcaster_htlc_key_arg, byte[] countersignatory_htlc_key_arg, byte[] broadcaster_delayed_payment_key_arg) {
115 long ret = bindings.TxCreationKeys_new(per_commitment_point_arg, revocation_key_arg, broadcaster_htlc_key_arg, countersignatory_htlc_key_arg, broadcaster_delayed_payment_key_arg);
116 if (ret < 1024) { return null; }
117 TxCreationKeys ret_hu_conv = new TxCreationKeys(null, ret);
118 ret_hu_conv.ptrs_to.add(ret_hu_conv);
123 * Creates a copy of the TxCreationKeys
125 public TxCreationKeys clone() {
126 long ret = bindings.TxCreationKeys_clone(this.ptr);
127 if (ret < 1024) { return null; }
128 TxCreationKeys ret_hu_conv = new TxCreationKeys(null, ret);
129 ret_hu_conv.ptrs_to.add(this);
134 * Serialize the TxCreationKeys object into a byte array which can be read by TxCreationKeys_read
136 public byte[] write() {
137 byte[] ret = bindings.TxCreationKeys_write(this.ptr);
142 * Read a TxCreationKeys from a byte array, created by TxCreationKeys_write
144 public static Result_TxCreationKeysDecodeErrorZ read(byte[] ser) {
145 long ret = bindings.TxCreationKeys_read(ser);
146 if (ret < 1024) { return null; }
147 Result_TxCreationKeysDecodeErrorZ ret_hu_conv = Result_TxCreationKeysDecodeErrorZ.constr_from_ptr(ret);
152 * Create per-state keys from channel base points and the per-commitment point.
153 * Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
155 public static Result_TxCreationKeysErrorZ derive_new(byte[] per_commitment_point, byte[] broadcaster_delayed_payment_base, byte[] broadcaster_htlc_base, byte[] countersignatory_revocation_base, byte[] countersignatory_htlc_base) {
156 long ret = bindings.TxCreationKeys_derive_new(per_commitment_point, broadcaster_delayed_payment_base, broadcaster_htlc_base, countersignatory_revocation_base, countersignatory_htlc_base);
157 if (ret < 1024) { return null; }
158 Result_TxCreationKeysErrorZ ret_hu_conv = Result_TxCreationKeysErrorZ.constr_from_ptr(ret);
163 * Generate per-state keys from channel static keys.
164 * Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
166 public static Result_TxCreationKeysErrorZ from_channel_static_keys(byte[] per_commitment_point, ChannelPublicKeys broadcaster_keys, ChannelPublicKeys countersignatory_keys) {
167 long ret = bindings.TxCreationKeys_from_channel_static_keys(per_commitment_point, broadcaster_keys == null ? 0 : broadcaster_keys.ptr & ~1, countersignatory_keys == null ? 0 : countersignatory_keys.ptr & ~1);
168 if (ret < 1024) { return null; }
169 Result_TxCreationKeysErrorZ ret_hu_conv = Result_TxCreationKeysErrorZ.constr_from_ptr(ret);
170 ret_hu_conv.ptrs_to.add(broadcaster_keys);
171 ret_hu_conv.ptrs_to.add(countersignatory_keys);