1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * BOLT 4 onion packet including hop data for the next peer.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class OnionPacket extends CommonBase {
16 OnionPacket(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.OnionPacket_free(ptr); }
24 * BOLT 4 version number.
26 public byte get_version() {
27 byte ret = bindings.OnionPacket_get_version(this.ptr);
28 Reference.reachabilityFence(this);
33 * BOLT 4 version number.
35 public void set_version(byte val) {
36 bindings.OnionPacket_set_version(this.ptr, val);
37 Reference.reachabilityFence(this);
38 Reference.reachabilityFence(val);
42 * In order to ensure we always return an error on onion decode in compliance with [BOLT
43 * #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to
44 * deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral
45 * public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd
48 * Returns a copy of the field.
50 public Result_PublicKeySecp256k1ErrorZ get_public_key() {
51 long ret = bindings.OnionPacket_get_public_key(this.ptr);
52 Reference.reachabilityFence(this);
53 if (ret >= 0 && ret <= 4096) { return null; }
54 Result_PublicKeySecp256k1ErrorZ ret_hu_conv = Result_PublicKeySecp256k1ErrorZ.constr_from_ptr(ret);
59 * In order to ensure we always return an error on onion decode in compliance with [BOLT
60 * #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to
61 * deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral
62 * public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd
65 public void set_public_key(org.ldk.structs.Result_PublicKeySecp256k1ErrorZ val) {
66 bindings.OnionPacket_set_public_key(this.ptr, val.ptr);
67 Reference.reachabilityFence(this);
68 Reference.reachabilityFence(val);
72 * HMAC to verify the integrity of hop_data.
74 public byte[] get_hmac() {
75 byte[] ret = bindings.OnionPacket_get_hmac(this.ptr);
76 Reference.reachabilityFence(this);
81 * HMAC to verify the integrity of hop_data.
83 public void set_hmac(byte[] val) {
84 bindings.OnionPacket_set_hmac(this.ptr, InternalUtils.check_arr_len(val, 32));
85 Reference.reachabilityFence(this);
86 Reference.reachabilityFence(val);
90 long ret = bindings.OnionPacket_clone_ptr(this.ptr);
91 Reference.reachabilityFence(this);
96 * Creates a copy of the OnionPacket
98 public OnionPacket clone() {
99 long ret = bindings.OnionPacket_clone(this.ptr);
100 Reference.reachabilityFence(this);
101 if (ret >= 0 && ret <= 4096) { return null; }
102 org.ldk.structs.OnionPacket ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OnionPacket(null, ret); }
103 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
108 * Generates a non-cryptographic 64-bit hash of the OnionPacket.
111 long ret = bindings.OnionPacket_hash(this.ptr);
112 Reference.reachabilityFence(this);
116 @Override public int hashCode() {
117 return (int)this.hash();
120 * Checks if two OnionPackets contain equal inner contents.
121 * This ignores pointers and is_owned flags and looks at the values in fields.
122 * Two objects with NULL inner values will be considered "equal" here.
124 public boolean eq(org.ldk.structs.OnionPacket b) {
125 boolean ret = bindings.OnionPacket_eq(this.ptr, b.ptr);
126 Reference.reachabilityFence(this);
127 Reference.reachabilityFence(b);
128 if (this != null) { this.ptrs_to.add(b); };
132 @Override public boolean equals(Object o) {
133 if (!(o instanceof OnionPacket)) return false;
134 return this.eq((OnionPacket)o);
137 * Serialize the OnionPacket object into a byte array which can be read by OnionPacket_read
139 public byte[] write() {
140 byte[] ret = bindings.OnionPacket_write(this.ptr);
141 Reference.reachabilityFence(this);
146 * Read a OnionPacket from a byte array, created by OnionPacket_write
148 public static Result_OnionPacketDecodeErrorZ read(byte[] ser) {
149 long ret = bindings.OnionPacket_read(ser);
150 Reference.reachabilityFence(ser);
151 if (ret >= 0 && ret <= 4096) { return null; }
152 Result_OnionPacketDecodeErrorZ ret_hu_conv = Result_OnionPacketDecodeErrorZ.constr_from_ptr(ret);