6 namespace org { namespace ldk { namespace structs {
10 * BOLT 4 onion packet including hop data for the next peer.
12 public class OnionPacket : CommonBase {
13 internal OnionPacket(object _dummy, long ptr) : base(ptr) { }
15 if (ptr != 0) { bindings.OnionPacket_free(ptr); }
19 * BOLT 4 version number.
21 public byte get_version() {
22 byte ret = bindings.OnionPacket_get_version(this.ptr);
28 * BOLT 4 version number.
30 public void set_version(byte val) {
31 bindings.OnionPacket_set_version(this.ptr, val);
37 * In order to ensure we always return an error on onion decode in compliance with [BOLT
38 * #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to
39 * deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral
40 * public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd
43 * Returns a copy of the field.
45 public Result_PublicKeySecp256k1ErrorZ get_public_key() {
46 long ret = bindings.OnionPacket_get_public_key(this.ptr);
48 if (ret >= 0 && ret <= 4096) { return null; }
49 Result_PublicKeySecp256k1ErrorZ ret_hu_conv = Result_PublicKeySecp256k1ErrorZ.constr_from_ptr(ret);
54 * In order to ensure we always return an error on onion decode in compliance with [BOLT
55 * #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to
56 * deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral
57 * public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd
60 public void set_public_key(org.ldk.structs.Result_PublicKeySecp256k1ErrorZ val) {
61 bindings.OnionPacket_set_public_key(this.ptr, val.ptr);
67 * HMAC to verify the integrity of hop_data.
69 public byte[] get_hmac() {
70 long ret = bindings.OnionPacket_get_hmac(this.ptr);
72 if (ret >= 0 && ret <= 4096) { return null; }
73 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
78 * HMAC to verify the integrity of hop_data.
80 public void set_hmac(byte[] val) {
81 bindings.OnionPacket_set_hmac(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 32)));
86 internal long clone_ptr() {
87 long ret = bindings.OnionPacket_clone_ptr(this.ptr);
93 * Creates a copy of the OnionPacket
95 public OnionPacket clone() {
96 long ret = bindings.OnionPacket_clone(this.ptr);
98 if (ret >= 0 && ret <= 4096) { return null; }
99 org.ldk.structs.OnionPacket ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OnionPacket(null, ret); }
100 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
105 * Generates a non-cryptographic 64-bit hash of the OnionPacket.
108 long ret = bindings.OnionPacket_hash(this.ptr);
113 public override int GetHashCode() {
114 return (int)this.hash();
117 * Checks if two OnionPackets contain equal inner contents.
118 * This ignores pointers and is_owned flags and looks at the values in fields.
119 * Two objects with NULL inner values will be considered "equal" here.
121 public bool eq(org.ldk.structs.OnionPacket b) {
122 bool ret = bindings.OnionPacket_eq(this.ptr, b.ptr);
125 if (this != null) { this.ptrs_to.AddLast(b); };
129 public override bool Equals(object o) {
130 if (!(o is OnionPacket)) return false;
131 return this.eq((OnionPacket)o);
134 * Serialize the OnionPacket object into a byte array which can be read by OnionPacket_read
136 public byte[] write() {
137 long ret = bindings.OnionPacket_write(this.ptr);
139 if (ret >= 0 && ret <= 4096) { return null; }
140 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
145 * Read a OnionPacket from a byte array, created by OnionPacket_write
147 public static Result_OnionPacketDecodeErrorZ read(byte[] ser) {
148 long ret = bindings.OnionPacket_read(InternalUtils.encodeUint8Array(ser));
150 if (ret >= 0 && ret <= 4096) { return null; }
151 Result_OnionPacketDecodeErrorZ ret_hu_conv = Result_OnionPacketDecodeErrorZ.constr_from_ptr(ret);