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 * The revocation key is used to allow a channel party to revoke their state - giving their
13 * counterparty the required material to claim all of their funds if they broadcast that state.
15 * Each commitment transaction has a revocation key based on the basepoint and
16 * per_commitment_point which is used in both commitment and HTLC transactions.
18 * See [the BOLT spec for derivation details]
19 * (https://github.com/lightning/bolts/blob/master/03-transactions.md#revocationpubkey-derivation)
21 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
22 public class RevocationKey extends CommonBase {
23 RevocationKey(Object _dummy, long ptr) { super(ptr); }
24 @Override @SuppressWarnings("deprecation")
25 protected void finalize() throws Throwable {
27 if (ptr != 0) { bindings.RevocationKey_free(ptr); }
30 public byte[] get_a() {
31 byte[] ret = bindings.RevocationKey_get_a(this.ptr);
32 Reference.reachabilityFence(this);
36 public void set_a(byte[] val) {
37 bindings.RevocationKey_set_a(this.ptr, InternalUtils.check_arr_len(val, 33));
38 Reference.reachabilityFence(this);
39 Reference.reachabilityFence(val);
43 * Constructs a new RevocationKey given each field
45 public static RevocationKey of(byte[] a_arg) {
46 long ret = bindings.RevocationKey_new(InternalUtils.check_arr_len(a_arg, 33));
47 Reference.reachabilityFence(a_arg);
48 if (ret >= 0 && ret <= 4096) { return null; }
49 org.ldk.structs.RevocationKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RevocationKey(null, ret); }
50 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
55 * Checks if two RevocationKeys contain equal inner contents.
56 * This ignores pointers and is_owned flags and looks at the values in fields.
57 * Two objects with NULL inner values will be considered "equal" here.
59 public boolean eq(org.ldk.structs.RevocationKey b) {
60 boolean ret = bindings.RevocationKey_eq(this.ptr, b == null ? 0 : b.ptr);
61 Reference.reachabilityFence(this);
62 Reference.reachabilityFence(b);
63 if (this != null) { this.ptrs_to.add(b); };
67 @Override public boolean equals(Object o) {
68 if (!(o instanceof RevocationKey)) return false;
69 return this.eq((RevocationKey)o);
72 long ret = bindings.RevocationKey_clone_ptr(this.ptr);
73 Reference.reachabilityFence(this);
78 * Creates a copy of the RevocationKey
80 public RevocationKey clone() {
81 long ret = bindings.RevocationKey_clone(this.ptr);
82 Reference.reachabilityFence(this);
83 if (ret >= 0 && ret <= 4096) { return null; }
84 org.ldk.structs.RevocationKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RevocationKey(null, ret); }
85 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
90 * Generates a non-cryptographic 64-bit hash of the RevocationKey.
93 long ret = bindings.RevocationKey_hash(this.ptr);
94 Reference.reachabilityFence(this);
98 @Override public int hashCode() {
99 return (int)this.hash();
102 * Derives a per-commitment-transaction revocation public key from one party's per-commitment
103 * point and the other party's [`RevocationBasepoint`]. This is the public equivalent of
104 * [`chan_utils::derive_private_revocation_key`] - using only public keys to derive a public
105 * key instead of private keys.
107 * Note that this is infallible iff we trust that at least one of the two input keys are randomly
108 * generated (ie our own).
110 * [`chan_utils::derive_private_revocation_key`]: crate::ln::chan_utils::derive_private_revocation_key
112 public static RevocationKey from_basepoint(org.ldk.structs.RevocationBasepoint countersignatory_basepoint, byte[] per_commitment_point) {
113 long ret = bindings.RevocationKey_from_basepoint(countersignatory_basepoint == null ? 0 : countersignatory_basepoint.ptr, InternalUtils.check_arr_len(per_commitment_point, 33));
114 Reference.reachabilityFence(countersignatory_basepoint);
115 Reference.reachabilityFence(per_commitment_point);
116 if (ret >= 0 && ret <= 4096) { return null; }
117 org.ldk.structs.RevocationKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RevocationKey(null, ret); }
118 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
119 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(countersignatory_basepoint); };
124 * Get inner Public Key
126 public byte[] to_public_key() {
127 byte[] ret = bindings.RevocationKey_to_public_key(this.ptr);
128 Reference.reachabilityFence(this);
133 * Serialize the RevocationKey object into a byte array which can be read by RevocationKey_read
135 public byte[] write() {
136 byte[] ret = bindings.RevocationKey_write(this.ptr);
137 Reference.reachabilityFence(this);
142 * Read a RevocationKey from a byte array, created by RevocationKey_write
144 public static Result_RevocationKeyDecodeErrorZ read(byte[] ser) {
145 long ret = bindings.RevocationKey_read(ser);
146 Reference.reachabilityFence(ser);
147 if (ret >= 0 && ret <= 4096) { return null; }
148 Result_RevocationKeyDecodeErrorZ ret_hu_conv = Result_RevocationKeyDecodeErrorZ.constr_from_ptr(ret);