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`, 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 IntroductionNode get_introduction_node() {
32 long ret = bindings.BlindedPath_get_introduction_node(this.ptr);
33 Reference.reachabilityFence(this);
34 if (ret >= 0 && ret <= 4096) { return null; }
35 org.ldk.structs.IntroductionNode ret_hu_conv = org.ldk.structs.IntroductionNode.constr_from_ptr(ret);
36 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
41 * To send to a blinded path, the sender first finds a route to the unblinded
42 * `introduction_node`, which can unblind its [`encrypted_payload`] to find out the onion
43 * message or payment's next hop and forward it along.
45 * [`encrypted_payload`]: BlindedHop::encrypted_payload
47 public void set_introduction_node(org.ldk.structs.IntroductionNode val) {
48 bindings.BlindedPath_set_introduction_node(this.ptr, val.ptr);
49 Reference.reachabilityFence(this);
50 Reference.reachabilityFence(val);
51 if (this != null) { this.ptrs_to.add(val); };
55 * Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion
58 * [`encrypted_payload`]: BlindedHop::encrypted_payload
60 public byte[] get_blinding_point() {
61 byte[] ret = bindings.BlindedPath_get_blinding_point(this.ptr);
62 Reference.reachabilityFence(this);
67 * Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion
70 * [`encrypted_payload`]: BlindedHop::encrypted_payload
72 public void set_blinding_point(byte[] val) {
73 bindings.BlindedPath_set_blinding_point(this.ptr, InternalUtils.check_arr_len(val, 33));
74 Reference.reachabilityFence(this);
75 Reference.reachabilityFence(val);
79 * The hops composing the blinded path.
81 public BlindedHop[] get_blinded_hops() {
82 long[] ret = bindings.BlindedPath_get_blinded_hops(this.ptr);
83 Reference.reachabilityFence(this);
84 int ret_conv_12_len = ret.length;
85 BlindedHop[] ret_conv_12_arr = new BlindedHop[ret_conv_12_len];
86 for (int m = 0; m < ret_conv_12_len; m++) {
87 long ret_conv_12 = ret[m];
88 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); }
89 if (ret_conv_12_hu_conv != null) { ret_conv_12_hu_conv.ptrs_to.add(this); };
90 ret_conv_12_arr[m] = ret_conv_12_hu_conv;
92 return ret_conv_12_arr;
96 * The hops composing the blinded path.
98 public void set_blinded_hops(BlindedHop[] val) {
99 bindings.BlindedPath_set_blinded_hops(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_12 -> val_conv_12.ptr).toArray() : null);
100 Reference.reachabilityFence(this);
101 Reference.reachabilityFence(val);
102 for (BlindedHop val_conv_12: val) { if (this != null) { this.ptrs_to.add(val_conv_12); }; };
106 * Constructs a new BlindedPath given each field
108 public static BlindedPath of(org.ldk.structs.IntroductionNode introduction_node_arg, byte[] blinding_point_arg, BlindedHop[] blinded_hops_arg) {
109 long ret = bindings.BlindedPath_new(introduction_node_arg.ptr, 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.ptr).toArray() : null);
110 Reference.reachabilityFence(introduction_node_arg);
111 Reference.reachabilityFence(blinding_point_arg);
112 Reference.reachabilityFence(blinded_hops_arg);
113 if (ret >= 0 && ret <= 4096) { return null; }
114 org.ldk.structs.BlindedPath ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedPath(null, ret); }
115 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
116 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(introduction_node_arg); };
117 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); }; };
122 long ret = bindings.BlindedPath_clone_ptr(this.ptr);
123 Reference.reachabilityFence(this);
128 * Creates a copy of the BlindedPath
130 public BlindedPath clone() {
131 long ret = bindings.BlindedPath_clone(this.ptr);
132 Reference.reachabilityFence(this);
133 if (ret >= 0 && ret <= 4096) { return null; }
134 org.ldk.structs.BlindedPath ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedPath(null, ret); }
135 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
140 * Generates a non-cryptographic 64-bit hash of the BlindedPath.
143 long ret = bindings.BlindedPath_hash(this.ptr);
144 Reference.reachabilityFence(this);
148 @Override public int hashCode() {
149 return (int)this.hash();
152 * Checks if two BlindedPaths contain equal inner contents.
153 * This ignores pointers and is_owned flags and looks at the values in fields.
154 * Two objects with NULL inner values will be considered "equal" here.
156 public boolean eq(org.ldk.structs.BlindedPath b) {
157 boolean ret = bindings.BlindedPath_eq(this.ptr, b.ptr);
158 Reference.reachabilityFence(this);
159 Reference.reachabilityFence(b);
160 if (this != null) { this.ptrs_to.add(b); };
164 @Override public boolean equals(Object o) {
165 if (!(o instanceof BlindedPath)) return false;
166 return this.eq((BlindedPath)o);
169 * Create a one-hop blinded path for a message.
171 public static Result_BlindedPathNoneZ one_hop_for_message(byte[] recipient_node_id, org.ldk.structs.EntropySource entropy_source) {
172 long ret = bindings.BlindedPath_one_hop_for_message(InternalUtils.check_arr_len(recipient_node_id, 33), entropy_source.ptr);
173 Reference.reachabilityFence(recipient_node_id);
174 Reference.reachabilityFence(entropy_source);
175 if (ret >= 0 && ret <= 4096) { return null; }
176 Result_BlindedPathNoneZ ret_hu_conv = Result_BlindedPathNoneZ.constr_from_ptr(ret);
177 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
182 * Create a blinded path for an onion message, to be forwarded along `node_pks`. The last node
183 * pubkey in `node_pks` will be the destination node.
185 * Errors if no hops are provided or if `node_pk`(s) are invalid.
187 public static Result_BlindedPathNoneZ new_for_message(byte[][] node_pks, org.ldk.structs.EntropySource entropy_source) {
188 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);
189 Reference.reachabilityFence(node_pks);
190 Reference.reachabilityFence(entropy_source);
191 if (ret >= 0 && ret <= 4096) { return null; }
192 Result_BlindedPathNoneZ ret_hu_conv = Result_BlindedPathNoneZ.constr_from_ptr(ret);
193 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
198 * Returns the introduction [`NodeId`] of the blinded path, if it is publicly reachable (i.e.,
199 * it is found in the network graph).
201 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
204 public NodeId public_introduction_node_id(org.ldk.structs.ReadOnlyNetworkGraph network_graph) {
205 long ret = bindings.BlindedPath_public_introduction_node_id(this.ptr, network_graph.ptr);
206 Reference.reachabilityFence(this);
207 Reference.reachabilityFence(network_graph);
208 if (ret >= 0 && ret <= 4096) { return null; }
209 org.ldk.structs.NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeId(null, ret); }
210 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
211 if (this != null) { this.ptrs_to.add(network_graph); };
216 * Serialize the BlindedPath object into a byte array which can be read by BlindedPath_read
218 public byte[] write() {
219 byte[] ret = bindings.BlindedPath_write(this.ptr);
220 Reference.reachabilityFence(this);
225 * Read a BlindedPath from a byte array, created by BlindedPath_write
227 public static Result_BlindedPathDecodeErrorZ read(byte[] ser) {
228 long ret = bindings.BlindedPath_read(ser);
229 Reference.reachabilityFence(ser);
230 if (ret >= 0 && ret <= 4096) { return null; }
231 Result_BlindedPathDecodeErrorZ ret_hu_conv = Result_BlindedPathDecodeErrorZ.constr_from_ptr(ret);