Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / UtilMethods.java
1 package org.ldk.structs;
2 import org.ldk.impl.bindings;
3 import java.util.Arrays;
4 import org.ldk.enums.*;
5
6 public class UtilMethods {
7         /**
8          * Creates a digital signature of a message given a SecretKey, like the node's secret.
9          * A receiver knowing the PublicKey (e.g. the node's id) and the message can be sure that the signature was generated by the caller.
10          * Signatures are EC recoverable, meaning that given the message and the signature the PublicKey of the signer can be extracted.
11          */
12         public static Result_StringErrorZ sign(byte[] msg, byte[] sk) {
13                 long ret = bindings.sign(msg, sk);
14                 Result_StringErrorZ ret_hu_conv = Result_StringErrorZ.constr_from_ptr(ret);
15                 return ret_hu_conv;
16         }
17
18         /**
19          * Recovers the PublicKey of the signer of the message given the message and the signature.
20          */
21         public static Result_PublicKeyErrorZ recover_pk(byte[] msg, String sig) {
22                 long ret = bindings.recover_pk(msg, sig);
23                 Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret);
24                 return ret_hu_conv;
25         }
26
27         /**
28          * Verifies a message was signed by a PrivateKey that derives to a given PublicKey, given a message, a signature,
29          * and the PublicKey.
30          */
31         public static boolean verify(byte[] msg, String sig, byte[] pk) {
32                 boolean ret = bindings.verify(msg, sig, pk);
33                 return ret;
34         }
35
36         /**
37          * Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
38          */
39         public static Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ BlockHashChannelMonitorZ_read(byte[] ser, KeysInterface arg) {
40                 long ret = bindings.C2Tuple_BlockHashChannelMonitorZ_read(ser, arg == null ? 0 : arg.ptr);
41                 Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.constr_from_ptr(ret);
42                 ret_hu_conv.ptrs_to.add(arg);
43                 return ret_hu_conv;
44         }
45
46         /**
47          * Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
48          */
49         public static Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ BlockHashChannelManagerZ_read(byte[] ser, KeysInterface arg_keys_manager, FeeEstimator arg_fee_estimator, Watch arg_chain_monitor, BroadcasterInterface arg_tx_broadcaster, Logger arg_logger, UserConfig arg_default_config, ChannelMonitor[] arg_channel_monitors) {
50                 long ret = bindings.C2Tuple_BlockHashChannelManagerZ_read(ser, bindings.ChannelManagerReadArgs_new(arg_keys_manager == null ? 0 : arg_keys_manager.ptr, arg_fee_estimator == null ? 0 : arg_fee_estimator.ptr, arg_chain_monitor == null ? 0 : arg_chain_monitor.ptr, arg_tx_broadcaster == null ? 0 : arg_tx_broadcaster.ptr, arg_logger == null ? 0 : arg_logger.ptr, arg_default_config == null ? 0 : arg_default_config.ptr & ~1, Arrays.stream(arg_channel_monitors).mapToLong(arg_channel_monitors_conv_16 -> arg_channel_monitors_conv_16 == null ? 0 : arg_channel_monitors_conv_16.ptr & ~1).toArray()));
51                 Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ ret_hu_conv = Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.constr_from_ptr(ret);
52                 ret_hu_conv.ptrs_to.add(arg_keys_manager);
53                 ret_hu_conv.ptrs_to.add(arg_fee_estimator);
54                 ret_hu_conv.ptrs_to.add(arg_chain_monitor);
55                 ret_hu_conv.ptrs_to.add(arg_tx_broadcaster);
56                 ret_hu_conv.ptrs_to.add(arg_logger);
57                 ret_hu_conv.ptrs_to.add(arg_default_config);
58                 /* TODO 2 ChannelMonitor  */;
59                 return ret_hu_conv;
60         }
61
62         /**
63          * Build the commitment secret from the seed and the commitment number
64          */
65         public static byte[] build_commitment_secret(byte[] commitment_seed, long idx) {
66                 byte[] ret = bindings.build_commitment_secret(commitment_seed, idx);
67                 return ret;
68         }
69
70         /**
71          * Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key)
72          * from the base secret and the per_commitment_point.
73          * 
74          * Note that this is infallible iff we trust that at least one of the two input keys are randomly
75          * generated (ie our own).
76          */
77         public static Result_SecretKeyErrorZ derive_private_key(byte[] per_commitment_point, byte[] base_secret) {
78                 long ret = bindings.derive_private_key(per_commitment_point, base_secret);
79                 Result_SecretKeyErrorZ ret_hu_conv = Result_SecretKeyErrorZ.constr_from_ptr(ret);
80                 return ret_hu_conv;
81         }
82
83         /**
84          * Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key)
85          * from the base point and the per_commitment_key. This is the public equivalent of
86          * derive_private_key - using only public keys to derive a public key instead of private keys.
87          * 
88          * Note that this is infallible iff we trust that at least one of the two input keys are randomly
89          * generated (ie our own).
90          */
91         public static Result_PublicKeyErrorZ derive_public_key(byte[] per_commitment_point, byte[] base_point) {
92                 long ret = bindings.derive_public_key(per_commitment_point, base_point);
93                 Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret);
94                 return ret_hu_conv;
95         }
96
97         /**
98          * Derives a per-commitment-transaction revocation key from its constituent parts.
99          * 
100          * Only the cheating participant owns a valid witness to propagate a revoked
101          * commitment transaction, thus per_commitment_secret always come from cheater
102          * and revocation_base_secret always come from punisher, which is the broadcaster
103          * of the transaction spending with this key knowledge.
104          * 
105          * Note that this is infallible iff we trust that at least one of the two input keys are randomly
106          * generated (ie our own).
107          */
108         public static Result_SecretKeyErrorZ derive_private_revocation_key(byte[] per_commitment_secret, byte[] countersignatory_revocation_base_secret) {
109                 long ret = bindings.derive_private_revocation_key(per_commitment_secret, countersignatory_revocation_base_secret);
110                 Result_SecretKeyErrorZ ret_hu_conv = Result_SecretKeyErrorZ.constr_from_ptr(ret);
111                 return ret_hu_conv;
112         }
113
114         /**
115          * Derives a per-commitment-transaction revocation public key from its constituent parts. This is
116          * the public equivalend of derive_private_revocation_key - using only public keys to derive a
117          * public key instead of private keys.
118          * 
119          * Only the cheating participant owns a valid witness to propagate a revoked
120          * commitment transaction, thus per_commitment_point always come from cheater
121          * and revocation_base_point always come from punisher, which is the broadcaster
122          * of the transaction spending with this key knowledge.
123          * 
124          * Note that this is infallible iff we trust that at least one of the two input keys are randomly
125          * generated (ie our own).
126          */
127         public static Result_PublicKeyErrorZ derive_public_revocation_key(byte[] per_commitment_point, byte[] countersignatory_revocation_base_point) {
128                 long ret = bindings.derive_public_revocation_key(per_commitment_point, countersignatory_revocation_base_point);
129                 Result_PublicKeyErrorZ ret_hu_conv = Result_PublicKeyErrorZ.constr_from_ptr(ret);
130                 return ret_hu_conv;
131         }
132
133         /**
134          * A script either spendable by the revocation
135          * key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
136          * Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
137          */
138         public static byte[] get_revokeable_redeemscript(byte[] revocation_key, short contest_delay, byte[] broadcaster_delayed_payment_key) {
139                 byte[] ret = bindings.get_revokeable_redeemscript(revocation_key, contest_delay, broadcaster_delayed_payment_key);
140                 return ret;
141         }
142
143         /**
144          * Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc
145          * does not need to have its previous_output_index filled.
146          */
147         public static byte[] get_htlc_redeemscript(HTLCOutputInCommitment htlc, TxCreationKeys keys) {
148                 byte[] ret = bindings.get_htlc_redeemscript(htlc == null ? 0 : htlc.ptr & ~1, keys == null ? 0 : keys.ptr & ~1);
149                 // this.ptrs_to.add(htlc);
150                 // this.ptrs_to.add(keys);
151                 return ret;
152         }
153
154         /**
155          * Gets the redeemscript for a funding output from the two funding public keys.
156          * Note that the order of funding public keys does not matter.
157          */
158         public static byte[] make_funding_redeemscript(byte[] broadcaster, byte[] countersignatory) {
159                 byte[] ret = bindings.make_funding_redeemscript(broadcaster, countersignatory);
160                 return ret;
161         }
162
163         /**
164          * Builds an unsigned HTLC-Success or HTLC-Timeout transaction from the given channel and HTLC
165          * parameters. This is used by [`TrustedCommitmentTransaction::get_htlc_sigs`] to fetch the
166          * transaction which needs signing, and can be used to construct an HTLC transaction which is
167          * broadcastable given a counterparty HTLC signature.
168          * 
169          * Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the
170          * commitment transaction).
171          */
172         public static byte[] build_htlc_transaction(byte[] commitment_txid, int feerate_per_kw, short contest_delay, HTLCOutputInCommitment htlc, byte[] broadcaster_delayed_payment_key, byte[] revocation_key) {
173                 byte[] ret = bindings.build_htlc_transaction(commitment_txid, feerate_per_kw, contest_delay, htlc == null ? 0 : htlc.ptr & ~1, broadcaster_delayed_payment_key, revocation_key);
174                 // this.ptrs_to.add(htlc);
175                 return ret;
176         }
177
178         /**
179          * Commitment transaction numbers which appear in the transactions themselves are XOR'd with a
180          * shared secret first. This prevents on-chain observers from discovering how many commitment
181          * transactions occurred in a channel before it was closed.
182          * 
183          * This function gets the shared secret from relevant channel public keys and can be used to
184          * \"decrypt\" the commitment transaction number given a commitment transaction on-chain.
185          */
186         public static long get_commitment_transaction_number_obscure_factor(byte[] broadcaster_payment_basepoint, byte[] countersignatory_payment_basepoint, boolean outbound_from_broadcaster) {
187                 long ret = bindings.get_commitment_transaction_number_obscure_factor(broadcaster_payment_basepoint, countersignatory_payment_basepoint, outbound_from_broadcaster);
188                 return ret;
189         }
190
191         /**
192          * Gets a route from us (payer) to the given target node (payee).
193          * 
194          * If the payee provided features in their invoice, they should be provided via payee_features.
195          * Without this, MPP will only be used if the payee's features are available in the network graph.
196          * 
197          * Private routing paths between a public node and the target may be included in `last_hops`.
198          * Currently, only the last hop in each path is considered.
199          * 
200          * If some channels aren't announced, it may be useful to fill in a first_hops with the
201          * results from a local ChannelManager::list_usable_channels() call. If it is filled in, our
202          * view of our local channels (from net_graph_msg_handler) will be ignored, and only those
203          * in first_hops will be used.
204          * 
205          * Panics if first_hops contains channels without short_channel_ids
206          * (ChannelManager::list_usable_channels will never include such channels).
207          * 
208          * The fees on channels from us to next-hops are ignored (as they are assumed to all be
209          * equal), however the enabled/disabled bit on such channels as well as the
210          * htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node.
211          */
212         public static Result_RouteLightningErrorZ get_route(byte[] our_node_id, NetworkGraph network, byte[] payee, InvoiceFeatures payee_features, ChannelDetails[] first_hops, RouteHint[] last_hops, long final_value_msat, int final_cltv, Logger logger) {
213                 long ret = bindings.get_route(our_node_id, network == null ? 0 : network.ptr & ~1, payee, payee_features == null ? 0 : payee_features.ptr & ~1, Arrays.stream(first_hops).mapToLong(first_hops_conv_16 -> first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr & ~1).toArray(), Arrays.stream(last_hops).mapToLong(last_hops_conv_11 -> last_hops_conv_11 == null ? 0 : last_hops_conv_11.ptr & ~1).toArray(), final_value_msat, final_cltv, logger == null ? 0 : logger.ptr);
214                 Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret);
215                 ret_hu_conv.ptrs_to.add(network);
216                 ret_hu_conv.ptrs_to.add(payee_features);
217                 /* TODO 2 ChannelDetails  */;
218                 /* TODO 2 RouteHint  */;
219                 ret_hu_conv.ptrs_to.add(logger);
220                 return ret_hu_conv;
221         }
222
223         /**
224          * Writes the provided `ChannelManager` to the path provided at `FilesystemPersister`
225          * initialization, within a file called \"manager\".
226          */
227         public static Result_NoneErrorZ FilesystemPersister_persist_manager(String data_dir, ChannelManager manager) {
228                 long ret = bindings.FilesystemPersister_persist_manager(data_dir, manager == null ? 0 : manager.ptr & ~1);
229                 Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret);
230                 ret_hu_conv.ptrs_to.add(manager);
231                 return ret_hu_conv;
232         }
233
234         /**
235          * Utility to construct an invoice. Generally, unless you want to do something like a custom
236          * cltv_expiry, this is what you should be using to create an invoice. The reason being, this
237          * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user
238          * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify
239          * that the payment secret is valid when the invoice is paid.
240          */
241         public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager(ChannelManager channelmanager, KeysInterface keys_manager, Currency network, Option_u64Z amt_msat, String description) {
242                 long ret = bindings.create_invoice_from_channelmanager(channelmanager == null ? 0 : channelmanager.ptr & ~1, keys_manager == null ? 0 : keys_manager.ptr, network, amt_msat.ptr, description);
243                 Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret);
244                 ret_hu_conv.ptrs_to.add(channelmanager);
245                 ret_hu_conv.ptrs_to.add(keys_manager);
246                 return ret_hu_conv;
247         }
248
249 }