[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / RevocationKey.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
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.
14  * 
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.
17  * 
18  * See [the BOLT spec for derivation details]
19  * (https://github.com/lightning/bolts/blob/master/03-transactions.md#revocationpubkey-derivation)
20  */
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 {
26                 super.finalize();
27                 if (ptr != 0) { bindings.RevocationKey_free(ptr); }
28         }
29
30         public byte[] get_a() {
31                 byte[] ret = bindings.RevocationKey_get_a(this.ptr);
32                 Reference.reachabilityFence(this);
33                 return ret;
34         }
35
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);
40         }
41
42         /**
43          * Constructs a new RevocationKey given each field
44          */
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); };
51                 return ret_hu_conv;
52         }
53
54         /**
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.
58          */
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); };
64                 return ret;
65         }
66
67         @Override public boolean equals(Object o) {
68                 if (!(o instanceof RevocationKey)) return false;
69                 return this.eq((RevocationKey)o);
70         }
71         long clone_ptr() {
72                 long ret = bindings.RevocationKey_clone_ptr(this.ptr);
73                 Reference.reachabilityFence(this);
74                 return ret;
75         }
76
77         /**
78          * Creates a copy of the RevocationKey
79          */
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); };
86                 return ret_hu_conv;
87         }
88
89         /**
90          * Generates a non-cryptographic 64-bit hash of the RevocationKey.
91          */
92         public long hash() {
93                 long ret = bindings.RevocationKey_hash(this.ptr);
94                 Reference.reachabilityFence(this);
95                 return ret;
96         }
97
98         @Override public int hashCode() {
99                 return (int)this.hash();
100         }
101         /**
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.
106          * 
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).
109          * 
110          * [`chan_utils::derive_private_revocation_key`]: crate::ln::chan_utils::derive_private_revocation_key
111          */
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); };
120                 return ret_hu_conv;
121         }
122
123         /**
124          * Get inner Public Key
125          */
126         public byte[] to_public_key() {
127                 byte[] ret = bindings.RevocationKey_to_public_key(this.ptr);
128                 Reference.reachabilityFence(this);
129                 return ret;
130         }
131
132         /**
133          * Serialize the RevocationKey object into a byte array which can be read by RevocationKey_read
134          */
135         public byte[] write() {
136                 byte[] ret = bindings.RevocationKey_write(this.ptr);
137                 Reference.reachabilityFence(this);
138                 return ret;
139         }
140
141         /**
142          * Read a RevocationKey from a byte array, created by RevocationKey_write
143          */
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);
149                 return ret_hu_conv;
150         }
151
152 }