[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / RevocationKey.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8
9 /**
10  * The revocation key is used to allow a channel party to revoke their state - giving their
11  * counterparty the required material to claim all of their funds if they broadcast that state.
12  * 
13  * Each commitment transaction has a revocation key based on the basepoint and
14  * per_commitment_point which is used in both commitment and HTLC transactions.
15  * 
16  * See [the BOLT spec for derivation details]
17  * (https://github.com/lightning/bolts/blob/master/03-transactions.md#revocationpubkey-derivation)
18  */
19 public class RevocationKey : CommonBase {
20         internal RevocationKey(object _dummy, long ptr) : base(ptr) { }
21         ~RevocationKey() {
22                 if (ptr != 0) { bindings.RevocationKey_free(ptr); }
23         }
24
25         public byte[] get_a() {
26                 long ret = bindings.RevocationKey_get_a(this.ptr);
27                 GC.KeepAlive(this);
28                 if (ret >= 0 && ret <= 4096) { return null; }
29                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
30                 return ret_conv;
31         }
32
33         public void set_a(byte[] val) {
34                 bindings.RevocationKey_set_a(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 33)));
35                 GC.KeepAlive(this);
36                 GC.KeepAlive(val);
37         }
38
39         /**
40          * Constructs a new RevocationKey given each field
41          */
42         public static RevocationKey of(byte[] a_arg) {
43                 long ret = bindings.RevocationKey_new(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(a_arg, 33)));
44                 GC.KeepAlive(a_arg);
45                 if (ret >= 0 && ret <= 4096) { return null; }
46                 org.ldk.structs.RevocationKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RevocationKey(null, ret); }
47                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
48                 return ret_hu_conv;
49         }
50
51         /**
52          * Checks if two RevocationKeys 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.
55          */
56         public bool eq(org.ldk.structs.RevocationKey b) {
57                 bool ret = bindings.RevocationKey_eq(this.ptr, b == null ? 0 : b.ptr);
58                 GC.KeepAlive(this);
59                 GC.KeepAlive(b);
60                 if (this != null) { this.ptrs_to.AddLast(b); };
61                 return ret;
62         }
63
64         public override bool Equals(object o) {
65                 if (!(o is RevocationKey)) return false;
66                 return this.eq((RevocationKey)o);
67         }
68         internal long clone_ptr() {
69                 long ret = bindings.RevocationKey_clone_ptr(this.ptr);
70                 GC.KeepAlive(this);
71                 return ret;
72         }
73
74         /**
75          * Creates a copy of the RevocationKey
76          */
77         public RevocationKey clone() {
78                 long ret = bindings.RevocationKey_clone(this.ptr);
79                 GC.KeepAlive(this);
80                 if (ret >= 0 && ret <= 4096) { return null; }
81                 org.ldk.structs.RevocationKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RevocationKey(null, ret); }
82                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
83                 return ret_hu_conv;
84         }
85
86         /**
87          * Generates a non-cryptographic 64-bit hash of the RevocationKey.
88          */
89         public long hash() {
90                 long ret = bindings.RevocationKey_hash(this.ptr);
91                 GC.KeepAlive(this);
92                 return ret;
93         }
94
95         public override int GetHashCode() {
96                 return (int)this.hash();
97         }
98         /**
99          * Derives a per-commitment-transaction revocation public key from one party's per-commitment
100          * point and the other party's [`RevocationBasepoint`]. This is the public equivalent of
101          * [`chan_utils::derive_private_revocation_key`] - using only public keys to derive a public
102          * key instead of private keys.
103          * 
104          * Note that this is infallible iff we trust that at least one of the two input keys are randomly
105          * generated (ie our own).
106          * 
107          * [`chan_utils::derive_private_revocation_key`]: crate::ln::chan_utils::derive_private_revocation_key
108          */
109         public static RevocationKey from_basepoint(org.ldk.structs.RevocationBasepoint countersignatory_basepoint, byte[] per_commitment_point) {
110                 long ret = bindings.RevocationKey_from_basepoint(countersignatory_basepoint == null ? 0 : countersignatory_basepoint.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(per_commitment_point, 33)));
111                 GC.KeepAlive(countersignatory_basepoint);
112                 GC.KeepAlive(per_commitment_point);
113                 if (ret >= 0 && ret <= 4096) { return null; }
114                 org.ldk.structs.RevocationKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RevocationKey(null, ret); }
115                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
116                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(countersignatory_basepoint); };
117                 return ret_hu_conv;
118         }
119
120         /**
121          * Get inner Public Key
122          */
123         public byte[] to_public_key() {
124                 long ret = bindings.RevocationKey_to_public_key(this.ptr);
125                 GC.KeepAlive(this);
126                 if (ret >= 0 && ret <= 4096) { return null; }
127                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
128                 return ret_conv;
129         }
130
131         /**
132          * Serialize the RevocationKey object into a byte array which can be read by RevocationKey_read
133          */
134         public byte[] write() {
135                 long ret = bindings.RevocationKey_write(this.ptr);
136                 GC.KeepAlive(this);
137                 if (ret >= 0 && ret <= 4096) { return null; }
138                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
139                 return ret_conv;
140         }
141
142         /**
143          * Read a RevocationKey from a byte array, created by RevocationKey_write
144          */
145         public static Result_RevocationKeyDecodeErrorZ read(byte[] ser) {
146                 long ret = bindings.RevocationKey_read(InternalUtils.encodeUint8Array(ser));
147                 GC.KeepAlive(ser);
148                 if (ret >= 0 && ret <= 4096) { return null; }
149                 Result_RevocationKeyDecodeErrorZ ret_hu_conv = Result_RevocationKeyDecodeErrorZ.constr_from_ptr(ret);
150                 return ret_hu_conv;
151         }
152
153 }
154 } } }