ba7ab4e14c5942ee3b445d00c10d447926236281
[ldk-java] / c_sharp / src / org / ldk / structs / TxCreationKeys.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 set of public keys which are used in the creation of one commitment transaction.
11  * These are derived from the channel base keys and per-commitment data.
12  * 
13  * A broadcaster key is provided from potential broadcaster of the computed transaction.
14  * A countersignatory key is coming from a protocol participant unable to broadcast the
15  * transaction.
16  * 
17  * These keys are assumed to be good, either because the code derived them from
18  * channel basepoints via the new function, or they were obtained via
19  * CommitmentTransaction.trust().keys() because we trusted the source of the
20  * pre-calculated keys.
21  */
22 public class TxCreationKeys : CommonBase {
23         internal TxCreationKeys(object _dummy, long ptr) : base(ptr) { }
24         ~TxCreationKeys() {
25                 if (ptr != 0) { bindings.TxCreationKeys_free(ptr); }
26         }
27
28         /**
29          * The broadcaster's per-commitment public key which was used to derive the other keys.
30          */
31         public byte[] get_per_commitment_point() {
32                 long ret = bindings.TxCreationKeys_get_per_commitment_point(this.ptr);
33                 GC.KeepAlive(this);
34                 if (ret >= 0 && ret <= 4096) { return null; }
35                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
36                 return ret_conv;
37         }
38
39         /**
40          * The broadcaster's per-commitment public key which was used to derive the other keys.
41          */
42         public void set_per_commitment_point(byte[] val) {
43                 bindings.TxCreationKeys_set_per_commitment_point(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 33)));
44                 GC.KeepAlive(this);
45                 GC.KeepAlive(val);
46         }
47
48         /**
49          * The revocation key which is used to allow the broadcaster of the commitment
50          * transaction to provide their counterparty the ability to punish them if they broadcast
51          * an old state.
52          */
53         public byte[] get_revocation_key() {
54                 long ret = bindings.TxCreationKeys_get_revocation_key(this.ptr);
55                 GC.KeepAlive(this);
56                 if (ret >= 0 && ret <= 4096) { return null; }
57                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
58                 return ret_conv;
59         }
60
61         /**
62          * The revocation key which is used to allow the broadcaster of the commitment
63          * transaction to provide their counterparty the ability to punish them if they broadcast
64          * an old state.
65          */
66         public void set_revocation_key(byte[] val) {
67                 bindings.TxCreationKeys_set_revocation_key(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 33)));
68                 GC.KeepAlive(this);
69                 GC.KeepAlive(val);
70         }
71
72         /**
73          * Broadcaster's HTLC Key
74          */
75         public byte[] get_broadcaster_htlc_key() {
76                 long ret = bindings.TxCreationKeys_get_broadcaster_htlc_key(this.ptr);
77                 GC.KeepAlive(this);
78                 if (ret >= 0 && ret <= 4096) { return null; }
79                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
80                 return ret_conv;
81         }
82
83         /**
84          * Broadcaster's HTLC Key
85          */
86         public void set_broadcaster_htlc_key(byte[] val) {
87                 bindings.TxCreationKeys_set_broadcaster_htlc_key(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 33)));
88                 GC.KeepAlive(this);
89                 GC.KeepAlive(val);
90         }
91
92         /**
93          * Countersignatory's HTLC Key
94          */
95         public byte[] get_countersignatory_htlc_key() {
96                 long ret = bindings.TxCreationKeys_get_countersignatory_htlc_key(this.ptr);
97                 GC.KeepAlive(this);
98                 if (ret >= 0 && ret <= 4096) { return null; }
99                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
100                 return ret_conv;
101         }
102
103         /**
104          * Countersignatory's HTLC Key
105          */
106         public void set_countersignatory_htlc_key(byte[] val) {
107                 bindings.TxCreationKeys_set_countersignatory_htlc_key(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 33)));
108                 GC.KeepAlive(this);
109                 GC.KeepAlive(val);
110         }
111
112         /**
113          * Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
114          */
115         public byte[] get_broadcaster_delayed_payment_key() {
116                 long ret = bindings.TxCreationKeys_get_broadcaster_delayed_payment_key(this.ptr);
117                 GC.KeepAlive(this);
118                 if (ret >= 0 && ret <= 4096) { return null; }
119                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
120                 return ret_conv;
121         }
122
123         /**
124          * Broadcaster's Payment Key (which isn't allowed to be spent from for some delay)
125          */
126         public void set_broadcaster_delayed_payment_key(byte[] val) {
127                 bindings.TxCreationKeys_set_broadcaster_delayed_payment_key(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 33)));
128                 GC.KeepAlive(this);
129                 GC.KeepAlive(val);
130         }
131
132         /**
133          * Constructs a new TxCreationKeys given each field
134          */
135         public static TxCreationKeys of(byte[] per_commitment_point_arg, byte[] revocation_key_arg, byte[] broadcaster_htlc_key_arg, byte[] countersignatory_htlc_key_arg, byte[] broadcaster_delayed_payment_key_arg) {
136                 long ret = bindings.TxCreationKeys_new(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(per_commitment_point_arg, 33)), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(revocation_key_arg, 33)), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(broadcaster_htlc_key_arg, 33)), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(countersignatory_htlc_key_arg, 33)), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(broadcaster_delayed_payment_key_arg, 33)));
137                 GC.KeepAlive(per_commitment_point_arg);
138                 GC.KeepAlive(revocation_key_arg);
139                 GC.KeepAlive(broadcaster_htlc_key_arg);
140                 GC.KeepAlive(countersignatory_htlc_key_arg);
141                 GC.KeepAlive(broadcaster_delayed_payment_key_arg);
142                 if (ret >= 0 && ret <= 4096) { return null; }
143                 org.ldk.structs.TxCreationKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.TxCreationKeys(null, ret); }
144                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
145                 return ret_hu_conv;
146         }
147
148         /**
149          * Checks if two TxCreationKeyss contain equal inner contents.
150          * This ignores pointers and is_owned flags and looks at the values in fields.
151          * Two objects with NULL inner values will be considered "equal" here.
152          */
153         public bool eq(org.ldk.structs.TxCreationKeys b) {
154                 bool ret = bindings.TxCreationKeys_eq(this.ptr, b == null ? 0 : b.ptr);
155                 GC.KeepAlive(this);
156                 GC.KeepAlive(b);
157                 if (this != null) { this.ptrs_to.AddLast(b); };
158                 return ret;
159         }
160
161         public override bool Equals(object o) {
162                 if (!(o is TxCreationKeys)) return false;
163                 return this.eq((TxCreationKeys)o);
164         }
165         internal long clone_ptr() {
166                 long ret = bindings.TxCreationKeys_clone_ptr(this.ptr);
167                 GC.KeepAlive(this);
168                 return ret;
169         }
170
171         /**
172          * Creates a copy of the TxCreationKeys
173          */
174         public TxCreationKeys clone() {
175                 long ret = bindings.TxCreationKeys_clone(this.ptr);
176                 GC.KeepAlive(this);
177                 if (ret >= 0 && ret <= 4096) { return null; }
178                 org.ldk.structs.TxCreationKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.TxCreationKeys(null, ret); }
179                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
180                 return ret_hu_conv;
181         }
182
183         /**
184          * Serialize the TxCreationKeys object into a byte array which can be read by TxCreationKeys_read
185          */
186         public byte[] write() {
187                 long ret = bindings.TxCreationKeys_write(this.ptr);
188                 GC.KeepAlive(this);
189                 if (ret >= 0 && ret <= 4096) { return null; }
190                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
191                 return ret_conv;
192         }
193
194         /**
195          * Read a TxCreationKeys from a byte array, created by TxCreationKeys_write
196          */
197         public static Result_TxCreationKeysDecodeErrorZ read(byte[] ser) {
198                 long ret = bindings.TxCreationKeys_read(InternalUtils.encodeUint8Array(ser));
199                 GC.KeepAlive(ser);
200                 if (ret >= 0 && ret <= 4096) { return null; }
201                 Result_TxCreationKeysDecodeErrorZ ret_hu_conv = Result_TxCreationKeysDecodeErrorZ.constr_from_ptr(ret);
202                 return ret_hu_conv;
203         }
204
205         /**
206          * Create per-state keys from channel base points and the per-commitment point.
207          * Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
208          */
209         public static TxCreationKeys derive_new(byte[] per_commitment_point, byte[] broadcaster_delayed_payment_base, byte[] broadcaster_htlc_base, byte[] countersignatory_revocation_base, byte[] countersignatory_htlc_base) {
210                 long ret = bindings.TxCreationKeys_derive_new(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(per_commitment_point, 33)), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(broadcaster_delayed_payment_base, 33)), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(broadcaster_htlc_base, 33)), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(countersignatory_revocation_base, 33)), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(countersignatory_htlc_base, 33)));
211                 GC.KeepAlive(per_commitment_point);
212                 GC.KeepAlive(broadcaster_delayed_payment_base);
213                 GC.KeepAlive(broadcaster_htlc_base);
214                 GC.KeepAlive(countersignatory_revocation_base);
215                 GC.KeepAlive(countersignatory_htlc_base);
216                 if (ret >= 0 && ret <= 4096) { return null; }
217                 org.ldk.structs.TxCreationKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.TxCreationKeys(null, ret); }
218                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
219                 return ret_hu_conv;
220         }
221
222         /**
223          * Generate per-state keys from channel static keys.
224          * Key set is asymmetric and can't be used as part of counter-signatory set of transactions.
225          */
226         public static TxCreationKeys from_channel_static_keys(byte[] per_commitment_point, org.ldk.structs.ChannelPublicKeys broadcaster_keys, org.ldk.structs.ChannelPublicKeys countersignatory_keys) {
227                 long ret = bindings.TxCreationKeys_from_channel_static_keys(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(per_commitment_point, 33)), broadcaster_keys == null ? 0 : broadcaster_keys.ptr, countersignatory_keys == null ? 0 : countersignatory_keys.ptr);
228                 GC.KeepAlive(per_commitment_point);
229                 GC.KeepAlive(broadcaster_keys);
230                 GC.KeepAlive(countersignatory_keys);
231                 if (ret >= 0 && ret <= 4096) { return null; }
232                 org.ldk.structs.TxCreationKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.TxCreationKeys(null, ret); }
233                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
234                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(broadcaster_keys); };
235                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(countersignatory_keys); };
236                 return ret_hu_conv;
237         }
238
239 }
240 } } }