6 namespace org { namespace ldk { namespace structs {
10 * A derived key built from a [`HtlcBasepoint`] and `per_commitment_point`.
12 * HTLC keys are used to ensure only the recipient of an HTLC can claim it on-chain with the HTLC
13 * preimage and that only the sender of an HTLC can claim it on-chain after it has timed out.
14 * Thus, both channel counterparties' HTLC keys will appears in each HTLC output's script.
16 * [See the BOLT specs]
17 * (https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation)
18 * for more information on key derivation details.
20 public class HtlcKey : CommonBase {
21 internal HtlcKey(object _dummy, long ptr) : base(ptr) { }
23 if (ptr != 0) { bindings.HtlcKey_free(ptr); }
26 public byte[] get_a() {
27 long ret = bindings.HtlcKey_get_a(this.ptr);
29 if (ret >= 0 && ret <= 4096) { return null; }
30 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
34 public void set_a(byte[] val) {
35 bindings.HtlcKey_set_a(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 33)));
41 * Constructs a new HtlcKey given each field
43 public static HtlcKey of(byte[] a_arg) {
44 long ret = bindings.HtlcKey_new(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(a_arg, 33)));
46 if (ret >= 0 && ret <= 4096) { return null; }
47 org.ldk.structs.HtlcKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.HtlcKey(null, ret); }
48 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
53 * Checks if two HtlcKeys contain equal inner contents.
54 * This ignores pointers and is_owned flags and looks at the values in fields.
55 * Two objects with NULL inner values will be considered "equal" here.
57 public bool eq(org.ldk.structs.HtlcKey b) {
58 bool ret = bindings.HtlcKey_eq(this.ptr, b == null ? 0 : b.ptr);
61 if (this != null) { this.ptrs_to.AddLast(b); };
65 public override bool Equals(object o) {
66 if (!(o is HtlcKey)) return false;
67 return this.eq((HtlcKey)o);
69 internal long clone_ptr() {
70 long ret = bindings.HtlcKey_clone_ptr(this.ptr);
76 * Creates a copy of the HtlcKey
78 public HtlcKey clone() {
79 long ret = bindings.HtlcKey_clone(this.ptr);
81 if (ret >= 0 && ret <= 4096) { return null; }
82 org.ldk.structs.HtlcKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.HtlcKey(null, ret); }
83 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
88 * Derive a public htlcpubkey using one node\'s `per_commitment_point` and its countersignatory\'s `basepoint`
90 public static HtlcKey from_basepoint(org.ldk.structs.HtlcBasepoint countersignatory_basepoint, byte[] per_commitment_point) {
91 long ret = bindings.HtlcKey_from_basepoint(countersignatory_basepoint == null ? 0 : countersignatory_basepoint.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(per_commitment_point, 33)));
92 GC.KeepAlive(countersignatory_basepoint);
93 GC.KeepAlive(per_commitment_point);
94 if (ret >= 0 && ret <= 4096) { return null; }
95 org.ldk.structs.HtlcKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.HtlcKey(null, ret); }
96 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
97 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(countersignatory_basepoint); };
102 * Build a htlcpubkey directly from an already-derived private key
104 public static HtlcKey from_secret_key(byte[] sk) {
105 long ret = bindings.HtlcKey_from_secret_key(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(sk, 32)));
107 if (ret >= 0 && ret <= 4096) { return null; }
108 org.ldk.structs.HtlcKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.HtlcKey(null, ret); }
109 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
114 * Get inner Public Key
116 public byte[] to_public_key() {
117 long ret = bindings.HtlcKey_to_public_key(this.ptr);
119 if (ret >= 0 && ret <= 4096) { return null; }
120 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
125 * Serialize the HtlcKey object into a byte array which can be read by HtlcKey_read
127 public byte[] write() {
128 long ret = bindings.HtlcKey_write(this.ptr);
130 if (ret >= 0 && ret <= 4096) { return null; }
131 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
136 * Read a HtlcKey from a byte array, created by HtlcKey_write
138 public static Result_HtlcKeyDecodeErrorZ read(byte[] ser) {
139 long ret = bindings.HtlcKey_read(InternalUtils.encodeUint8Array(ser));
141 if (ret >= 0 && ret <= 4096) { return null; }
142 Result_HtlcKeyDecodeErrorZ ret_hu_conv = Result_HtlcKeyDecodeErrorZ.constr_from_ptr(ret);