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