Package org.ldk.structs
Class UtilMethods
- java.lang.Object
-
- org.ldk.structs.UtilMethods
-
public class UtilMethods extends Object
-
-
Constructor Summary
Constructors Constructor Description UtilMethods()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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)
Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_writestatic Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ
BlockHashChannelMonitorZ_read(byte[] ser, KeysInterface arg)
Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_writestatic byte[]
build_closing_transaction(long to_holder_value_sat, long to_counterparty_value_sat, byte[] to_holder_script, byte[] to_counterparty_script, OutPoint funding_outpoint)
Build a closing transactionstatic byte[]
build_commitment_secret(byte[] commitment_seed, long idx)
Build the commitment secret from the seed and the commitment numberstatic byte[]
build_htlc_transaction(byte[] commitment_txid, int feerate_per_kw, short contest_delay, HTLCOutputInCommitment htlc, byte[] broadcaster_delayed_payment_key, byte[] revocation_key)
Builds an unsigned HTLC-Success or HTLC-Timeout transaction from the given channel and HTLC parameters.static Result_InvoiceSignOrCreationErrorZ
create_invoice_from_channelmanager(ChannelManager channelmanager, KeysInterface keys_manager, Currency network, Option_u64Z amt_msat, String description)
Utility to construct an invoice.static Result_SecretKeyErrorZ
derive_private_key(byte[] per_commitment_point, byte[] base_secret)
Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key) from the base secret and the per_commitment_point.static Result_SecretKeyErrorZ
derive_private_revocation_key(byte[] per_commitment_secret, byte[] countersignatory_revocation_base_secret)
Derives a per-commitment-transaction revocation key from its constituent parts.static Result_PublicKeyErrorZ
derive_public_key(byte[] per_commitment_point, byte[] base_point)
Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key) from the base point and the per_commitment_key.static Result_PublicKeyErrorZ
derive_public_revocation_key(byte[] per_commitment_point, byte[] countersignatory_revocation_base_point)
Derives a per-commitment-transaction revocation public key from its constituent parts.static Result_NoneErrorZ
FilesystemPersister_persist_manager(String data_dir, ChannelManager manager)
Writes the provided `ChannelManager` to the path provided at `FilesystemPersister` initialization, within a file called \"manager\".static long
get_commitment_transaction_number_obscure_factor(byte[] broadcaster_payment_basepoint, byte[] countersignatory_payment_basepoint, boolean outbound_from_broadcaster)
Commitment transaction numbers which appear in the transactions themselves are XOR'd with a shared secret first.static byte[]
get_htlc_redeemscript(HTLCOutputInCommitment htlc, TxCreationKeys keys)
Gets the witness redeemscript for an HTLC output in a commitment transaction.static Result_RouteLightningErrorZ
get_keysend_route(byte[] our_node_id, NetworkGraph network, byte[] payee, ChannelDetails[] first_hops, RouteHint[] last_hops, long final_value_msat, int final_cltv, Logger logger)
Gets a keysend route from us (payer) to the given target node (payee).static byte[]
get_revokeable_redeemscript(byte[] revocation_key, short contest_delay, byte[] broadcaster_delayed_payment_key)
A script either spendable by the revocation key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.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)
Gets a route from us (payer) to the given target node (payee).static byte[]
make_funding_redeemscript(byte[] broadcaster, byte[] countersignatory)
Gets the redeemscript for a funding output from the two funding public keys.static Result_PublicKeyErrorZ
recover_pk(byte[] msg, String sig)
Recovers the PublicKey of the signer of the message given the message and the signature.static Result_StringErrorZ
sign(byte[] msg, byte[] sk)
Creates a digital signature of a message given a SecretKey, like the node's secret.static boolean
verify(byte[] msg, String sig, byte[] pk)
Verifies a message was signed by a PrivateKey that derives to a given PublicKey, given a message, a signature, and the PublicKey.
-
-
-
Method Detail
-
sign
public static Result_StringErrorZ sign(byte[] msg, byte[] sk)
Creates a digital signature of a message given a SecretKey, like the node's secret. 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. Signatures are EC recoverable, meaning that given the message and the signature the PublicKey of the signer can be extracted.
-
recover_pk
public static Result_PublicKeyErrorZ recover_pk(byte[] msg, String sig)
Recovers the PublicKey of the signer of the message given the message and the signature.
-
verify
public static boolean verify(byte[] msg, String sig, byte[] pk)
Verifies a message was signed by a PrivateKey that derives to a given PublicKey, given a message, a signature, and the PublicKey.
-
BlockHashChannelMonitorZ_read
public static Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ BlockHashChannelMonitorZ_read(byte[] ser, KeysInterface arg)
Read a C2Tuple_BlockHashChannelMonitorZ from a byte array, created by C2Tuple_BlockHashChannelMonitorZ_write
-
BlockHashChannelManagerZ_read
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)
Read a C2Tuple_BlockHashChannelManagerZ from a byte array, created by C2Tuple_BlockHashChannelManagerZ_write
-
build_commitment_secret
public static byte[] build_commitment_secret(byte[] commitment_seed, long idx)
Build the commitment secret from the seed and the commitment number
-
build_closing_transaction
public static byte[] build_closing_transaction(long to_holder_value_sat, long to_counterparty_value_sat, byte[] to_holder_script, byte[] to_counterparty_script, OutPoint funding_outpoint)
Build a closing transaction
-
derive_private_key
public static Result_SecretKeyErrorZ derive_private_key(byte[] per_commitment_point, byte[] base_secret)
Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key) from the base secret and the per_commitment_point. Note that this is infallible iff we trust that at least one of the two input keys are randomly generated (ie our own).
-
derive_public_key
public static Result_PublicKeyErrorZ derive_public_key(byte[] per_commitment_point, byte[] base_point)
Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key) from the base point and the per_commitment_key. This is the public equivalent of derive_private_key - using only public keys to derive a public key instead of private keys. Note that this is infallible iff we trust that at least one of the two input keys are randomly generated (ie our own).
-
derive_private_revocation_key
public static Result_SecretKeyErrorZ derive_private_revocation_key(byte[] per_commitment_secret, byte[] countersignatory_revocation_base_secret)
Derives a per-commitment-transaction revocation key from its constituent parts. Only the cheating participant owns a valid witness to propagate a revoked commitment transaction, thus per_commitment_secret always come from cheater and revocation_base_secret always come from punisher, which is the broadcaster of the transaction spending with this key knowledge. Note that this is infallible iff we trust that at least one of the two input keys are randomly generated (ie our own).
-
derive_public_revocation_key
public static Result_PublicKeyErrorZ derive_public_revocation_key(byte[] per_commitment_point, byte[] countersignatory_revocation_base_point)
Derives a per-commitment-transaction revocation public key from its constituent parts. This is the public equivalend of derive_private_revocation_key - using only public keys to derive a public key instead of private keys. Only the cheating participant owns a valid witness to propagate a revoked commitment transaction, thus per_commitment_point always come from cheater and revocation_base_point always come from punisher, which is the broadcaster of the transaction spending with this key knowledge. Note that this is infallible iff we trust that at least one of the two input keys are randomly generated (ie our own).
-
get_revokeable_redeemscript
public static byte[] get_revokeable_redeemscript(byte[] revocation_key, short contest_delay, byte[] broadcaster_delayed_payment_key)
A script either spendable by the revocation key or the broadcaster_delayed_payment_key and satisfying the relative-locktime OP_CSV constrain. Encumbering a `to_holder` output on a commitment transaction or 2nd-stage HTLC transactions.
-
get_htlc_redeemscript
public static byte[] get_htlc_redeemscript(HTLCOutputInCommitment htlc, TxCreationKeys keys)
Gets the witness redeemscript for an HTLC output in a commitment transaction. Note that htlc does not need to have its previous_output_index filled.
-
make_funding_redeemscript
public static byte[] make_funding_redeemscript(byte[] broadcaster, byte[] countersignatory)
Gets the redeemscript for a funding output from the two funding public keys. Note that the order of funding public keys does not matter.
-
build_htlc_transaction
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)
Builds an unsigned HTLC-Success or HTLC-Timeout transaction from the given channel and HTLC parameters. This is used by [`TrustedCommitmentTransaction::get_htlc_sigs`] to fetch the transaction which needs signing, and can be used to construct an HTLC transaction which is broadcastable given a counterparty HTLC signature. Panics if htlc.transaction_output_index.is_none() (as such HTLCs do not appear in the commitment transaction).
-
get_commitment_transaction_number_obscure_factor
public static long get_commitment_transaction_number_obscure_factor(byte[] broadcaster_payment_basepoint, byte[] countersignatory_payment_basepoint, boolean outbound_from_broadcaster)
Commitment transaction numbers which appear in the transactions themselves are XOR'd with a shared secret first. This prevents on-chain observers from discovering how many commitment transactions occurred in a channel before it was closed. This function gets the shared secret from relevant channel public keys and can be used to \"decrypt\" the commitment transaction number given a commitment transaction on-chain.
-
get_keysend_route
public static Result_RouteLightningErrorZ get_keysend_route(byte[] our_node_id, NetworkGraph network, byte[] payee, @Nullable ChannelDetails[] first_hops, RouteHint[] last_hops, long final_value_msat, int final_cltv, Logger logger)
Gets a keysend route from us (payer) to the given target node (payee). This is needed because keysend payments do not have an invoice from which to pull the payee's supported features, which makes it tricky to otherwise supply the `payee_features` parameter of `get_route`. Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
-
get_route
public static Result_RouteLightningErrorZ get_route(byte[] our_node_id, NetworkGraph network, byte[] payee, @Nullable InvoiceFeatures payee_features, @Nullable ChannelDetails[] first_hops, RouteHint[] last_hops, long final_value_msat, int final_cltv, Logger logger)
Gets a route from us (payer) to the given target node (payee). If the payee provided features in their invoice, they should be provided via payee_features. Without this, MPP will only be used if the payee's features are available in the network graph. Private routing paths between a public node and the target may be included in `last_hops`. Currently, only the last hop in each path is considered. If some channels aren't announced, it may be useful to fill in a first_hops with the results from a local ChannelManager::list_usable_channels() call. If it is filled in, our view of our local channels (from net_graph_msg_handler) will be ignored, and only those in first_hops will be used. Panics if first_hops contains channels without short_channel_ids (ChannelManager::list_usable_channels will never include such channels). The fees on channels from us to next-hops are ignored (as they are assumed to all be equal), however the enabled/disabled bit on such channels as well as the htlc_minimum_msat/htlc_maximum_msat *are* checked as they may change based on the receiving node. Note that payee_features (or a relevant inner pointer) may be NULL or all-0s to represent None Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None
-
FilesystemPersister_persist_manager
public static Result_NoneErrorZ FilesystemPersister_persist_manager(String data_dir, ChannelManager manager)
Writes the provided `ChannelManager` to the path provided at `FilesystemPersister` initialization, within a file called \"manager\".
-
create_invoice_from_channelmanager
public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager(ChannelManager channelmanager, KeysInterface keys_manager, Currency network, Option_u64Z amt_msat, String description)
Utility to construct an invoice. Generally, unless you want to do something like a custom cltv_expiry, this is what you should be using to create an invoice. The reason being, this method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify that the payment secret is valid when the invoice is paid.
-
-