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 * Base key used in conjunction with a `per_commitment_point` to generate a [`DelayedPaymentKey`].
14 * The delayed payment key is used to pay the commitment state broadcaster their
15 * non-HTLC-encumbered funds after a delay to give their counterparty a chance to punish if the
16 * state broadcasted was previously revoked.
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class DelayedPaymentBasepoint extends CommonBase {
20 DelayedPaymentBasepoint(Object _dummy, long ptr) { super(ptr); }
21 @Override @SuppressWarnings("deprecation")
22 protected void finalize() throws Throwable {
24 if (ptr != 0) { bindings.DelayedPaymentBasepoint_free(ptr); }
27 public byte[] get_a() {
28 byte[] ret = bindings.DelayedPaymentBasepoint_get_a(this.ptr);
29 Reference.reachabilityFence(this);
33 public void set_a(byte[] val) {
34 bindings.DelayedPaymentBasepoint_set_a(this.ptr, InternalUtils.check_arr_len(val, 33));
35 Reference.reachabilityFence(this);
36 Reference.reachabilityFence(val);
40 * Constructs a new DelayedPaymentBasepoint given each field
42 public static DelayedPaymentBasepoint of(byte[] a_arg) {
43 long ret = bindings.DelayedPaymentBasepoint_new(InternalUtils.check_arr_len(a_arg, 33));
44 Reference.reachabilityFence(a_arg);
45 if (ret >= 0 && ret <= 4096) { return null; }
46 org.ldk.structs.DelayedPaymentBasepoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentBasepoint(null, ret); }
47 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
52 * Checks if two DelayedPaymentBasepoints contain equal inner contents.
53 * This ignores pointers and is_owned flags and looks at the values in fields.
54 * Two objects with NULL inner values will be considered "equal" here.
56 public boolean eq(org.ldk.structs.DelayedPaymentBasepoint b) {
57 boolean ret = bindings.DelayedPaymentBasepoint_eq(this.ptr, b.ptr);
58 Reference.reachabilityFence(this);
59 Reference.reachabilityFence(b);
60 if (this != null) { this.ptrs_to.add(b); };
64 @Override public boolean equals(Object o) {
65 if (!(o instanceof DelayedPaymentBasepoint)) return false;
66 return this.eq((DelayedPaymentBasepoint)o);
69 long ret = bindings.DelayedPaymentBasepoint_clone_ptr(this.ptr);
70 Reference.reachabilityFence(this);
75 * Creates a copy of the DelayedPaymentBasepoint
77 public DelayedPaymentBasepoint clone() {
78 long ret = bindings.DelayedPaymentBasepoint_clone(this.ptr);
79 Reference.reachabilityFence(this);
80 if (ret >= 0 && ret <= 4096) { return null; }
81 org.ldk.structs.DelayedPaymentBasepoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentBasepoint(null, ret); }
82 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
87 * Generates a non-cryptographic 64-bit hash of the DelayedPaymentBasepoint.
90 long ret = bindings.DelayedPaymentBasepoint_hash(this.ptr);
91 Reference.reachabilityFence(this);
95 @Override public int hashCode() {
96 return (int)this.hash();
99 * Get inner Public Key
101 public byte[] to_public_key() {
102 byte[] ret = bindings.DelayedPaymentBasepoint_to_public_key(this.ptr);
103 Reference.reachabilityFence(this);
108 * Derives the \"tweak\" used in calculate [`DelayedPaymentKey::from_basepoint`].\n\n[`DelayedPaymentKey::from_basepoint`] calculates a private key as:\n`privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)`\n\nThis calculates the hash part in the tweak derivation process, which is used to\nensure that each key is unique and cannot be guessed by an external party.
110 public byte[] derive_add_tweak(byte[] per_commitment_point) {
111 byte[] ret = bindings.DelayedPaymentBasepoint_derive_add_tweak(this.ptr, InternalUtils.check_arr_len(per_commitment_point, 33));
112 Reference.reachabilityFence(this);
113 Reference.reachabilityFence(per_commitment_point);
118 * Serialize the DelayedPaymentBasepoint object into a byte array which can be read by DelayedPaymentBasepoint_read
120 public byte[] write() {
121 byte[] ret = bindings.DelayedPaymentBasepoint_write(this.ptr);
122 Reference.reachabilityFence(this);
127 * Read a DelayedPaymentBasepoint from a byte array, created by DelayedPaymentBasepoint_write
129 public static Result_DelayedPaymentBasepointDecodeErrorZ read(byte[] ser) {
130 long ret = bindings.DelayedPaymentBasepoint_read(ser);
131 Reference.reachabilityFence(ser);
132 if (ret >= 0 && ret <= 4096) { return null; }
133 Result_DelayedPaymentBasepointDecodeErrorZ ret_hu_conv = Result_DelayedPaymentBasepointDecodeErrorZ.constr_from_ptr(ret);