X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fstructs%2FUtilMethods.mts;fp=ts%2Fstructs%2FUtilMethods.mts;h=a584dfa8370641a463be7a938370c0ba3621175b;hb=f04dac7563c27cf03a3d7a45fdeb9e1202fa40cb;hp=021ef131faabff27f7e5b83f7f9a653f28d4fef8;hpb=4c43dd48d036ef8fd9e984ec74b5e66d4f1941f6;p=ldk-java diff --git a/ts/structs/UtilMethods.mts b/ts/structs/UtilMethods.mts index 021ef131..a584dfa8 100644 --- a/ts/structs/UtilMethods.mts +++ b/ts/structs/UtilMethods.mts @@ -52,6 +52,10 @@ import { Result_SpendableOutputDescriptorDecodeErrorZ } from '../structs/Result_ import { Option_u32Z } from '../structs/Option_u32Z.mjs'; import { TwoTuple_CVec_u8ZusizeZ } from '../structs/TwoTuple_CVec_u8ZusizeZ.mjs'; import { Result_C2Tuple_CVec_u8ZusizeZNoneZ } from '../structs/Result_C2Tuple_CVec_u8ZusizeZNoneZ.mjs'; +import { ChannelDerivationParameters } from '../structs/ChannelDerivationParameters.mjs'; +import { Result_ChannelDerivationParametersDecodeErrorZ } from '../structs/Result_ChannelDerivationParametersDecodeErrorZ.mjs'; +import { HTLCDescriptor } from '../structs/HTLCDescriptor.mjs'; +import { Result_HTLCDescriptorDecodeErrorZ } from '../structs/Result_HTLCDescriptorDecodeErrorZ.mjs'; import { Result_NoneNoneZ } from '../structs/Result_NoneNoneZ.mjs'; import { TwoTuple_ECDSASignatureCVec_ECDSASignatureZZ } from '../structs/TwoTuple_ECDSASignatureCVec_ECDSASignatureZZ.mjs'; import { Result_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ } from '../structs/Result_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ.mjs'; @@ -63,7 +67,6 @@ import { Result_SchnorrSignatureNoneZ } from '../structs/Result_SchnorrSignature import { CommitmentTransaction } from '../structs/CommitmentTransaction.mjs'; import { HolderCommitmentTransaction } from '../structs/HolderCommitmentTransaction.mjs'; import { HTLCOutputInCommitment } from '../structs/HTLCOutputInCommitment.mjs'; -import { HTLCDescriptor } from '../structs/HTLCDescriptor.mjs'; import { ClosingTransaction } from '../structs/ClosingTransaction.mjs'; import { UnsignedChannelAnnouncement } from '../structs/UnsignedChannelAnnouncement.mjs'; import { ChannelPublicKeys } from '../structs/ChannelPublicKeys.mjs'; @@ -201,9 +204,6 @@ import { NodeInfo } from '../structs/NodeInfo.mjs'; import { Result_NodeInfoDecodeErrorZ } from '../structs/Result_NodeInfoDecodeErrorZ.mjs'; import { Result_NetworkGraphDecodeErrorZ } from '../structs/Result_NetworkGraphDecodeErrorZ.mjs'; import { Option_CVec_SocketAddressZZ } from '../structs/Option_CVec_SocketAddressZZ.mjs'; -import { ChannelDerivationParameters } from '../structs/ChannelDerivationParameters.mjs'; -import { Result_ChannelDerivationParametersDecodeErrorZ } from '../structs/Result_ChannelDerivationParametersDecodeErrorZ.mjs'; -import { Result_HTLCDescriptorDecodeErrorZ } from '../structs/Result_HTLCDescriptorDecodeErrorZ.mjs'; import { Utxo } from '../structs/Utxo.mjs'; import { Option_TxOutZ } from '../structs/Option_TxOutZ.mjs'; import { Input } from '../structs/Input.mjs'; @@ -225,7 +225,16 @@ import { Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZPaymentSendFailureZ } from import { ProbeSendFailure } from '../structs/ProbeSendFailure.mjs'; import { Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ } from '../structs/Result_CVec_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZZProbeSendFailureZ.mjs'; import { TwoTuple_ThirtyTwoBytesPublicKeyZ } from '../structs/TwoTuple_ThirtyTwoBytesPublicKeyZ.mjs'; +import { Option_StrZ } from '../structs/Option_StrZ.mjs'; +import { Result_NoneBolt12SemanticErrorZ } from '../structs/Result_NoneBolt12SemanticErrorZ.mjs'; import { Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ } from '../structs/Result_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ.mjs'; +import { InvoiceRequest } from '../structs/InvoiceRequest.mjs'; +import { Bolt12Invoice } from '../structs/Bolt12Invoice.mjs'; +import { InvoiceError } from '../structs/InvoiceError.mjs'; +import { OffersMessage } from '../structs/OffersMessage.mjs'; +import { Option_OffersMessageZ } from '../structs/Option_OffersMessageZ.mjs'; +import { Destination } from '../structs/Destination.mjs'; +import { ThreeTuple_OffersMessageDestinationBlindedPathZ } from '../structs/ThreeTuple_OffersMessageDestinationBlindedPathZ.mjs'; import { CounterpartyForwardingInfo } from '../structs/CounterpartyForwardingInfo.mjs'; import { Result_CounterpartyForwardingInfoDecodeErrorZ } from '../structs/Result_CounterpartyForwardingInfoDecodeErrorZ.mjs'; import { ChannelCounterparty } from '../structs/ChannelCounterparty.mjs'; @@ -272,14 +281,10 @@ import { TwoTuple_ThirtyTwoBytesChannelMonitorZ } from '../structs/TwoTuple_Thir import { Result_C2Tuple_ThirtyTwoBytesChannelMonitorZDecodeErrorZ } from '../structs/Result_C2Tuple_ThirtyTwoBytesChannelMonitorZDecodeErrorZ.mjs'; import { Type, TypeInterface } from '../structs/Type.mjs'; import { TwoTuple_PublicKeyTypeZ } from '../structs/TwoTuple_PublicKeyTypeZ.mjs'; -import { InvoiceRequest } from '../structs/InvoiceRequest.mjs'; -import { Bolt12Invoice } from '../structs/Bolt12Invoice.mjs'; -import { InvoiceError } from '../structs/InvoiceError.mjs'; -import { OffersMessage } from '../structs/OffersMessage.mjs'; -import { Option_OffersMessageZ } from '../structs/Option_OffersMessageZ.mjs'; -import { CustomOnionMessageContents, CustomOnionMessageContentsInterface } from '../structs/CustomOnionMessageContents.mjs'; -import { Option_CustomOnionMessageContentsZ } from '../structs/Option_CustomOnionMessageContentsZ.mjs'; -import { Result_COption_CustomOnionMessageContentsZDecodeErrorZ } from '../structs/Result_COption_CustomOnionMessageContentsZDecodeErrorZ.mjs'; +import { OnionMessageContents, OnionMessageContentsInterface } from '../structs/OnionMessageContents.mjs'; +import { Option_OnionMessageContentsZ } from '../structs/Option_OnionMessageContentsZ.mjs'; +import { Result_COption_OnionMessageContentsZDecodeErrorZ } from '../structs/Result_COption_OnionMessageContentsZDecodeErrorZ.mjs'; +import { ThreeTuple_OnionMessageContentsDestinationBlindedPathZ } from '../structs/ThreeTuple_OnionMessageContentsDestinationBlindedPathZ.mjs'; import { Option_TypeZ } from '../structs/Option_TypeZ.mjs'; import { Result_COption_TypeZDecodeErrorZ } from '../structs/Result_COption_TypeZDecodeErrorZ.mjs'; import { Option_SocketAddressZ } from '../structs/Option_SocketAddressZ.mjs'; @@ -451,6 +456,9 @@ import { Result_OnionMessagePathNoneZ } from '../structs/Result_OnionMessagePath import { TwoTuple_PublicKeyOnionMessageZ } from '../structs/TwoTuple_PublicKeyOnionMessageZ.mjs'; import { SendError } from '../structs/SendError.mjs'; import { Result_C2Tuple_PublicKeyOnionMessageZSendErrorZ } from '../structs/Result_C2Tuple_PublicKeyOnionMessageZSendErrorZ.mjs'; +import { ParsedOnionMessageContents } from '../structs/ParsedOnionMessageContents.mjs'; +import { PeeledOnion } from '../structs/PeeledOnion.mjs'; +import { Result_PeeledOnionNoneZ } from '../structs/Result_PeeledOnionNoneZ.mjs'; import { Result_NoneSendErrorZ } from '../structs/Result_NoneSendErrorZ.mjs'; import { Result_BlindedPathNoneZ } from '../structs/Result_BlindedPathNoneZ.mjs'; import { Result_C2Tuple_BlindedPayInfoBlindedPathZNoneZ } from '../structs/Result_C2Tuple_BlindedPayInfoBlindedPathZNoneZ.mjs'; @@ -491,16 +499,15 @@ import { FailureCode } from '../structs/FailureCode.mjs'; import { ChainParameters } from '../structs/ChainParameters.mjs'; import { MessageSendEventsProvider, MessageSendEventsProviderInterface } from '../structs/MessageSendEventsProvider.mjs'; import { ChannelMessageHandler, ChannelMessageHandlerInterface } from '../structs/ChannelMessageHandler.mjs'; +import { OffersMessageHandler, OffersMessageHandlerInterface } from '../structs/OffersMessageHandler.mjs'; import { ChannelManagerReadArgs } from '../structs/ChannelManagerReadArgs.mjs'; import { ExpandedKey } from '../structs/ExpandedKey.mjs'; import { Packet } from '../structs/Packet.mjs'; import { RoutingMessageHandler, RoutingMessageHandlerInterface } from '../structs/RoutingMessageHandler.mjs'; -import { OnionMessageProvider, OnionMessageProviderInterface } from '../structs/OnionMessageProvider.mjs'; import { OnionMessageHandler, OnionMessageHandlerInterface } from '../structs/OnionMessageHandler.mjs'; import { CustomMessageReader, CustomMessageReaderInterface } from '../structs/CustomMessageReader.mjs'; import { CustomMessageHandler, CustomMessageHandlerInterface } from '../structs/CustomMessageHandler.mjs'; import { IgnoringMessageHandler } from '../structs/IgnoringMessageHandler.mjs'; -import { OffersMessageHandler, OffersMessageHandlerInterface } from '../structs/OffersMessageHandler.mjs'; import { CustomOnionMessageHandler, CustomOnionMessageHandlerInterface } from '../structs/CustomOnionMessageHandler.mjs'; import { ErroringMessageHandler } from '../structs/ErroringMessageHandler.mjs'; import { MessageHandler } from '../structs/MessageHandler.mjs'; @@ -527,11 +534,9 @@ import { MultiThreadedScoreLockWrite } from '../structs/MultiThreadedScoreLockWr import { ProbabilisticScoringDecayParameters } from '../structs/ProbabilisticScoringDecayParameters.mjs'; import { KeysManager } from '../structs/KeysManager.mjs'; import { PhantomKeysManager } from '../structs/PhantomKeysManager.mjs'; -import { Destination } from '../structs/Destination.mjs'; import { MessageRouter, MessageRouterInterface } from '../structs/MessageRouter.mjs'; import { OnionMessenger } from '../structs/OnionMessenger.mjs'; import { DefaultMessageRouter } from '../structs/DefaultMessageRouter.mjs'; -import { OnionMessageContents } from '../structs/OnionMessageContents.mjs'; import { ForwardNode } from '../structs/ForwardNode.mjs'; import { ForwardTlvs } from '../structs/ForwardTlvs.mjs'; import { CoinSelectionSource, CoinSelectionSourceInterface } from '../structs/CoinSelectionSource.mjs'; @@ -665,7 +670,7 @@ export class UtilMethods extends CommonBase { } /** - * Fetches the set of [`InitFeatures`] flags which are provided by or required by + * Fetches the set of [`InitFeatures`] flags that are provided by or required by * [`ChannelManager`]. */ public static constructor_provided_init_features(config: UserConfig): InitFeatures { @@ -1078,22 +1083,40 @@ export class UtilMethods extends CommonBase { } /** - * Create an onion message with contents `message` to the destination of `path`. - * Returns (introduction_node_id, onion_msg) + * Creates an [`OnionMessage`] with the given `contents` for sending to the destination of + * `path`. + * + * Returns both the node id of the peer to send the message to and the message itself. * * Note that reply_path (or a relevant inner pointer) may be NULL or all-0s to represent None */ - public static constructor_create_onion_message(entropy_source: EntropySource, node_signer: NodeSigner, path: OnionMessagePath, message: OnionMessageContents, reply_path: BlindedPath|null): Result_C2Tuple_PublicKeyOnionMessageZSendErrorZ { - const ret: bigint = bindings.create_onion_message(CommonBase.get_ptr_of(entropy_source), CommonBase.get_ptr_of(node_signer), path == null ? 0n : CommonBase.get_ptr_of(path), CommonBase.get_ptr_of(message), reply_path == null ? 0n : CommonBase.get_ptr_of(reply_path)); + public static constructor_create_onion_message(entropy_source: EntropySource, node_signer: NodeSigner, path: OnionMessagePath, contents: OnionMessageContents, reply_path: BlindedPath|null): Result_C2Tuple_PublicKeyOnionMessageZSendErrorZ { + const ret: bigint = bindings.create_onion_message(CommonBase.get_ptr_of(entropy_source), CommonBase.get_ptr_of(node_signer), path == null ? 0n : CommonBase.get_ptr_of(path), CommonBase.get_ptr_of(contents), reply_path == null ? 0n : CommonBase.get_ptr_of(reply_path)); const ret_hu_conv: Result_C2Tuple_PublicKeyOnionMessageZSendErrorZ = Result_C2Tuple_PublicKeyOnionMessageZSendErrorZ.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, entropy_source); CommonBase.add_ref_from(ret_hu_conv, node_signer); CommonBase.add_ref_from(ret_hu_conv, path); - CommonBase.add_ref_from(ret_hu_conv, message); + CommonBase.add_ref_from(ret_hu_conv, contents); CommonBase.add_ref_from(ret_hu_conv, reply_path); return ret_hu_conv; } + /** + * Decode one layer of an incoming [`OnionMessage`]. + * + * Returns either the next layer of the onion for forwarding or the decrypted content for the + * receiver. + */ + public static constructor_peel_onion_message(msg: OnionMessage, node_signer: NodeSigner, logger: Logger, custom_handler: CustomOnionMessageHandler): Result_PeeledOnionNoneZ { + const ret: bigint = bindings.peel_onion_message(msg == null ? 0n : CommonBase.get_ptr_of(msg), CommonBase.get_ptr_of(node_signer), CommonBase.get_ptr_of(logger), CommonBase.get_ptr_of(custom_handler)); + const ret_hu_conv: Result_PeeledOnionNoneZ = Result_PeeledOnionNoneZ.constr_from_ptr(ret); + CommonBase.add_ref_from(ret_hu_conv, msg); + CommonBase.add_ref_from(ret_hu_conv, node_signer); + CommonBase.add_ref_from(ret_hu_conv, logger); + CommonBase.add_ref_from(ret_hu_conv, custom_handler); + return ret_hu_conv; + } + /** * Returns whether `tlv_type` corresponds to a TLV record for Offers. */