6 namespace org { namespace ldk { namespace structs {
10 * A derived key built from a [`DelayedPaymentBasepoint`] and `per_commitment_point`.
12 * The delayed payment key is used to pay the commitment state broadcaster their
13 * non-HTLC-encumbered funds after a delay. This delay gives their counterparty a chance to
14 * punish and claim all the channel funds if the state broadcasted was previously revoked.
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 DelayedPaymentKey : CommonBase {
21 internal DelayedPaymentKey(object _dummy, long ptr) : base(ptr) { }
22 ~DelayedPaymentKey() {
23 if (ptr != 0) { bindings.DelayedPaymentKey_free(ptr); }
26 public byte[] get_a() {
27 long ret = bindings.DelayedPaymentKey_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.DelayedPaymentKey_set_a(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 33)));
41 * Constructs a new DelayedPaymentKey given each field
43 public static DelayedPaymentKey of(byte[] a_arg) {
44 long ret = bindings.DelayedPaymentKey_new(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(a_arg, 33)));
46 if (ret >= 0 && ret <= 4096) { return null; }
47 org.ldk.structs.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(null, ret); }
48 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
53 * Checks if two DelayedPaymentKeys 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.DelayedPaymentKey b) {
58 bool ret = bindings.DelayedPaymentKey_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 DelayedPaymentKey)) return false;
67 return this.eq((DelayedPaymentKey)o);
69 internal long clone_ptr() {
70 long ret = bindings.DelayedPaymentKey_clone_ptr(this.ptr);
76 * Creates a copy of the DelayedPaymentKey
78 public DelayedPaymentKey clone() {
79 long ret = bindings.DelayedPaymentKey_clone(this.ptr);
81 if (ret >= 0 && ret <= 4096) { return null; }
82 org.ldk.structs.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(null, ret); }
83 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
88 * Derive a public delayedpubkey using one node\'s `per_commitment_point` and its countersignatory\'s `basepoint`
90 public static DelayedPaymentKey from_basepoint(org.ldk.structs.DelayedPaymentBasepoint countersignatory_basepoint, byte[] per_commitment_point) {
91 long ret = bindings.DelayedPaymentKey_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.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(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 delayedpubkey directly from an already-derived private key
104 public static DelayedPaymentKey from_secret_key(byte[] sk) {
105 long ret = bindings.DelayedPaymentKey_from_secret_key(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(sk, 32)));
107 if (ret >= 0 && ret <= 4096) { return null; }
108 org.ldk.structs.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(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.DelayedPaymentKey_to_public_key(this.ptr);
119 if (ret >= 0 && ret <= 4096) { return null; }
120 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
125 * Serialize the DelayedPaymentKey object into a byte array which can be read by DelayedPaymentKey_read
127 public byte[] write() {
128 long ret = bindings.DelayedPaymentKey_write(this.ptr);
130 if (ret >= 0 && ret <= 4096) { return null; }
131 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
136 * Read a DelayedPaymentKey from a byte array, created by DelayedPaymentKey_write
138 public static Result_DelayedPaymentKeyDecodeErrorZ read(byte[] ser) {
139 long ret = bindings.DelayedPaymentKey_read(InternalUtils.encodeUint8Array(ser));
141 if (ret >= 0 && ret <= 4096) { return null; }
142 Result_DelayedPaymentKeyDecodeErrorZ ret_hu_conv = Result_DelayedPaymentKeyDecodeErrorZ.constr_from_ptr(ret);