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 * Onion messages and payments can be sent and received to blinded paths, which serve to hide the
13 * identity of the recipient.
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class BlindedPath extends CommonBase {
17 BlindedPath(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.BlindedPath_free(ptr); }
25 * To send to a blinded path, the sender first finds a route to the unblinded
26 * `introduction_node_id`, which can unblind its [`encrypted_payload`] to find out the onion
27 * message or payment's next hop and forward it along.
29 * [`encrypted_payload`]: BlindedHop::encrypted_payload
31 public byte[] get_introduction_node_id() {
32 byte[] ret = bindings.BlindedPath_get_introduction_node_id(this.ptr);
33 Reference.reachabilityFence(this);
38 * To send to a blinded path, the sender first finds a route to the unblinded
39 * `introduction_node_id`, which can unblind its [`encrypted_payload`] to find out the onion
40 * message or payment's next hop and forward it along.
42 * [`encrypted_payload`]: BlindedHop::encrypted_payload
44 public void set_introduction_node_id(byte[] val) {
45 bindings.BlindedPath_set_introduction_node_id(this.ptr, InternalUtils.check_arr_len(val, 33));
46 Reference.reachabilityFence(this);
47 Reference.reachabilityFence(val);
51 * Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion
54 * [`encrypted_payload`]: BlindedHop::encrypted_payload
56 public byte[] get_blinding_point() {
57 byte[] ret = bindings.BlindedPath_get_blinding_point(this.ptr);
58 Reference.reachabilityFence(this);
63 * Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion
66 * [`encrypted_payload`]: BlindedHop::encrypted_payload
68 public void set_blinding_point(byte[] val) {
69 bindings.BlindedPath_set_blinding_point(this.ptr, InternalUtils.check_arr_len(val, 33));
70 Reference.reachabilityFence(this);
71 Reference.reachabilityFence(val);
75 * The hops composing the blinded path.
77 public BlindedHop[] get_blinded_hops() {
78 long[] ret = bindings.BlindedPath_get_blinded_hops(this.ptr);
79 Reference.reachabilityFence(this);
80 int ret_conv_12_len = ret.length;
81 BlindedHop[] ret_conv_12_arr = new BlindedHop[ret_conv_12_len];
82 for (int m = 0; m < ret_conv_12_len; m++) {
83 long ret_conv_12 = ret[m];
84 org.ldk.structs.BlindedHop ret_conv_12_hu_conv = null; if (ret_conv_12 < 0 || ret_conv_12 > 4096) { ret_conv_12_hu_conv = new org.ldk.structs.BlindedHop(null, ret_conv_12); }
85 if (ret_conv_12_hu_conv != null) { ret_conv_12_hu_conv.ptrs_to.add(this); };
86 ret_conv_12_arr[m] = ret_conv_12_hu_conv;
88 return ret_conv_12_arr;
92 * The hops composing the blinded path.
94 public void set_blinded_hops(BlindedHop[] val) {
95 bindings.BlindedPath_set_blinded_hops(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_12 -> val_conv_12 == null ? 0 : val_conv_12.ptr).toArray() : null);
96 Reference.reachabilityFence(this);
97 Reference.reachabilityFence(val);
98 for (BlindedHop val_conv_12: val) { if (this != null) { this.ptrs_to.add(val_conv_12); }; };
102 * Constructs a new BlindedPath given each field
104 public static BlindedPath of(byte[] introduction_node_id_arg, byte[] blinding_point_arg, BlindedHop[] blinded_hops_arg) {
105 long ret = bindings.BlindedPath_new(InternalUtils.check_arr_len(introduction_node_id_arg, 33), InternalUtils.check_arr_len(blinding_point_arg, 33), blinded_hops_arg != null ? Arrays.stream(blinded_hops_arg).mapToLong(blinded_hops_arg_conv_12 -> blinded_hops_arg_conv_12 == null ? 0 : blinded_hops_arg_conv_12.ptr).toArray() : null);
106 Reference.reachabilityFence(introduction_node_id_arg);
107 Reference.reachabilityFence(blinding_point_arg);
108 Reference.reachabilityFence(blinded_hops_arg);
109 if (ret >= 0 && ret <= 4096) { return null; }
110 org.ldk.structs.BlindedPath ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedPath(null, ret); }
111 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
112 for (BlindedHop blinded_hops_arg_conv_12: blinded_hops_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(blinded_hops_arg_conv_12); }; };
117 long ret = bindings.BlindedPath_clone_ptr(this.ptr);
118 Reference.reachabilityFence(this);
123 * Creates a copy of the BlindedPath
125 public BlindedPath clone() {
126 long ret = bindings.BlindedPath_clone(this.ptr);
127 Reference.reachabilityFence(this);
128 if (ret >= 0 && ret <= 4096) { return null; }
129 org.ldk.structs.BlindedPath ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedPath(null, ret); }
130 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
135 * Generates a non-cryptographic 64-bit hash of the BlindedPath.
138 long ret = bindings.BlindedPath_hash(this.ptr);
139 Reference.reachabilityFence(this);
143 @Override public int hashCode() {
144 return (int)this.hash();
147 * Checks if two BlindedPaths contain equal inner contents.
148 * This ignores pointers and is_owned flags and looks at the values in fields.
149 * Two objects with NULL inner values will be considered "equal" here.
151 public boolean eq(org.ldk.structs.BlindedPath b) {
152 boolean ret = bindings.BlindedPath_eq(this.ptr, b == null ? 0 : b.ptr);
153 Reference.reachabilityFence(this);
154 Reference.reachabilityFence(b);
155 if (this != null) { this.ptrs_to.add(b); };
159 @Override public boolean equals(Object o) {
160 if (!(o instanceof BlindedPath)) return false;
161 return this.eq((BlindedPath)o);
164 * Create a one-hop blinded path for a message.
166 public static Result_BlindedPathNoneZ one_hop_for_message(byte[] recipient_node_id, org.ldk.structs.EntropySource entropy_source) {
167 long ret = bindings.BlindedPath_one_hop_for_message(InternalUtils.check_arr_len(recipient_node_id, 33), entropy_source.ptr);
168 Reference.reachabilityFence(recipient_node_id);
169 Reference.reachabilityFence(entropy_source);
170 if (ret >= 0 && ret <= 4096) { return null; }
171 Result_BlindedPathNoneZ ret_hu_conv = Result_BlindedPathNoneZ.constr_from_ptr(ret);
172 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
177 * Create a blinded path for an onion message, to be forwarded along `node_pks`. The last node
178 * pubkey in `node_pks` will be the destination node.
180 * Errors if no hops are provided or if `node_pk`(s) are invalid.
182 public static Result_BlindedPathNoneZ new_for_message(byte[][] node_pks, org.ldk.structs.EntropySource entropy_source) {
183 long ret = bindings.BlindedPath_new_for_message(node_pks != null ? Arrays.stream(node_pks).map(node_pks_conv_8 -> InternalUtils.check_arr_len(node_pks_conv_8, 33)).toArray(byte[][]::new) : null, entropy_source.ptr);
184 Reference.reachabilityFence(node_pks);
185 Reference.reachabilityFence(entropy_source);
186 if (ret >= 0 && ret <= 4096) { return null; }
187 Result_BlindedPathNoneZ ret_hu_conv = Result_BlindedPathNoneZ.constr_from_ptr(ret);
188 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
193 * Serialize the BlindedPath object into a byte array which can be read by BlindedPath_read
195 public byte[] write() {
196 byte[] ret = bindings.BlindedPath_write(this.ptr);
197 Reference.reachabilityFence(this);
202 * Read a BlindedPath from a byte array, created by BlindedPath_write
204 public static Result_BlindedPathDecodeErrorZ read(byte[] ser) {
205 long ret = bindings.BlindedPath_read(ser);
206 Reference.reachabilityFence(ser);
207 if (ret >= 0 && ret <= 4096) { return null; }
208 Result_BlindedPathDecodeErrorZ ret_hu_conv = Result_BlindedPathDecodeErrorZ.constr_from_ptr(ret);