1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * A derived key built from a [`DelayedPaymentBasepoint`] and `per_commitment_point`.
14 * The delayed payment key is used to pay the commitment state broadcaster their
15 * non-HTLC-encumbered funds after a delay. This delay gives their counterparty a chance to
16 * punish and claim all the channel funds if the state broadcasted was previously revoked.
18 * [See the BOLT specs]
19 * (https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation)
20 * for more information on key derivation details.
22 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
23 public class DelayedPaymentKey extends CommonBase {
24 DelayedPaymentKey(Object _dummy, long ptr) { super(ptr); }
25 @Override @SuppressWarnings("deprecation")
26 protected void finalize() throws Throwable {
28 if (ptr != 0) { bindings.DelayedPaymentKey_free(ptr); }
31 public byte[] get_a() {
32 byte[] ret = bindings.DelayedPaymentKey_get_a(this.ptr);
33 Reference.reachabilityFence(this);
37 public void set_a(byte[] val) {
38 bindings.DelayedPaymentKey_set_a(this.ptr, InternalUtils.check_arr_len(val, 33));
39 Reference.reachabilityFence(this);
40 Reference.reachabilityFence(val);
44 * Constructs a new DelayedPaymentKey given each field
46 public static DelayedPaymentKey of(byte[] a_arg) {
47 long ret = bindings.DelayedPaymentKey_new(InternalUtils.check_arr_len(a_arg, 33));
48 Reference.reachabilityFence(a_arg);
49 if (ret >= 0 && ret <= 4096) { return null; }
50 org.ldk.structs.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(null, ret); }
51 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
56 * Checks if two DelayedPaymentKeys contain equal inner contents.
57 * This ignores pointers and is_owned flags and looks at the values in fields.
58 * Two objects with NULL inner values will be considered "equal" here.
60 public boolean eq(org.ldk.structs.DelayedPaymentKey b) {
61 boolean ret = bindings.DelayedPaymentKey_eq(this.ptr, b == null ? 0 : b.ptr);
62 Reference.reachabilityFence(this);
63 Reference.reachabilityFence(b);
64 if (this != null) { this.ptrs_to.add(b); };
68 @Override public boolean equals(Object o) {
69 if (!(o instanceof DelayedPaymentKey)) return false;
70 return this.eq((DelayedPaymentKey)o);
73 long ret = bindings.DelayedPaymentKey_clone_ptr(this.ptr);
74 Reference.reachabilityFence(this);
79 * Creates a copy of the DelayedPaymentKey
81 public DelayedPaymentKey clone() {
82 long ret = bindings.DelayedPaymentKey_clone(this.ptr);
83 Reference.reachabilityFence(this);
84 if (ret >= 0 && ret <= 4096) { return null; }
85 org.ldk.structs.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(null, ret); }
86 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
91 * Derive a public delayedpubkey using one node\'s `per_commitment_point` and its countersignatory\'s `basepoint`
93 public static DelayedPaymentKey from_basepoint(org.ldk.structs.DelayedPaymentBasepoint countersignatory_basepoint, byte[] per_commitment_point) {
94 long ret = bindings.DelayedPaymentKey_from_basepoint(countersignatory_basepoint == null ? 0 : countersignatory_basepoint.ptr, InternalUtils.check_arr_len(per_commitment_point, 33));
95 Reference.reachabilityFence(countersignatory_basepoint);
96 Reference.reachabilityFence(per_commitment_point);
97 if (ret >= 0 && ret <= 4096) { return null; }
98 org.ldk.structs.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(null, ret); }
99 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
100 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(countersignatory_basepoint); };
105 * Build a delayedpubkey directly from an already-derived private key
107 public static DelayedPaymentKey from_secret_key(byte[] sk) {
108 long ret = bindings.DelayedPaymentKey_from_secret_key(InternalUtils.check_arr_len(sk, 32));
109 Reference.reachabilityFence(sk);
110 if (ret >= 0 && ret <= 4096) { return null; }
111 org.ldk.structs.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(null, ret); }
112 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
117 * Get inner Public Key
119 public byte[] to_public_key() {
120 byte[] ret = bindings.DelayedPaymentKey_to_public_key(this.ptr);
121 Reference.reachabilityFence(this);
126 * Serialize the DelayedPaymentKey object into a byte array which can be read by DelayedPaymentKey_read
128 public byte[] write() {
129 byte[] ret = bindings.DelayedPaymentKey_write(this.ptr);
130 Reference.reachabilityFence(this);
135 * Read a DelayedPaymentKey from a byte array, created by DelayedPaymentKey_write
137 public static Result_DelayedPaymentKeyDecodeErrorZ read(byte[] ser) {
138 long ret = bindings.DelayedPaymentKey_read(ser);
139 Reference.reachabilityFence(ser);
140 if (ret >= 0 && ret <= 4096) { return null; }
141 Result_DelayedPaymentKeyDecodeErrorZ ret_hu_conv = Result_DelayedPaymentKeyDecodeErrorZ.constr_from_ptr(ret);