UNPKG

lightningdevkit

Version:
1,001 lines (972 loc) 3.6 MB
import * as version from './version.mjs'; const imports = {}; imports.env = {}; var js_objs = []; var js_invoke; var getRandomValues; imports.wasi_snapshot_preview1 = { "fd_write": (fd, iovec_array_ptr, iovec_array_len, bytes_written_ptr) => { // This should generally only be used to print panic messages const ptr_len_view = new Uint32Array(wasm.memory.buffer, iovec_array_ptr, iovec_array_len * 2); var bytes_written = 0; for (var i = 0; i < iovec_array_len; i++) { const bytes_view = new Uint8Array(wasm.memory.buffer, ptr_len_view[i * 2], ptr_len_view[i * 2 + 1]); console.log("[fd " + fd + "]: " + String.fromCharCode(...bytes_view)); bytes_written += ptr_len_view[i * 2 + 1]; } const written_view = new Uint32Array(wasm.memory.buffer, bytes_written_ptr, 1); written_view[0] = bytes_written; return 0; }, "fd_close": (_fd) => { // This is not generally called, but may be referenced in debug builds console.log("wasi_snapshot_preview1:fd_close"); return 58; // Not Supported }, "fd_seek": (_fd, _offset, _whence, _new_offset) => { // This is not generally called, but may be referenced in debug builds console.log("wasi_snapshot_preview1:fd_seek"); return 58; // Not Supported }, "random_get": (buf_ptr, buf_len) => { const buf = new Uint8Array(wasm.memory.buffer, buf_ptr, buf_len); getRandomValues(buf); return 0; }, "environ_sizes_get": (environ_var_count_ptr, environ_len_ptr) => { // This is called before fd_write to format + print panic messages const out_count_view = new Uint32Array(wasm.memory.buffer, environ_var_count_ptr, 1); out_count_view[0] = 0; const out_len_view = new Uint32Array(wasm.memory.buffer, environ_len_ptr, 1); out_len_view[0] = 0; return 0; }, "environ_get": (_environ_ptr, _environ_buf_ptr) => { // This is called before fd_write to format + print panic messages, // but only if we have variables in environ_sizes_get, so shouldn't ever actually happen! console.log("wasi_snapshot_preview1:environ_get"); return 58; // Note supported - we said there were 0 environment entries! }, "proc_exit": () => { console.log("wasi_snapshot_preview1:proc_exit"); }, }; var wasm = null; let isWasmInitialized = false; async function finishInitializeWasm(wasmInstance) { if (typeof crypto === "undefined") { var crypto_import = (await import('crypto')).webcrypto; getRandomValues = crypto_import.getRandomValues.bind(crypto_import); } else { getRandomValues = crypto.getRandomValues.bind(crypto); } wasm = wasmInstance.exports; if (!wasm.test_bigint_pass_deadbeef0badf00d(BigInt("0xdeadbeef0badf00d"))) { throw new Error("Currently need BigInt-as-u64 support, try ----experimental-wasm-bigint"); } if (decodeString(wasm.TS_get_lib_version_string()) !== version.get_ldk_java_bindings_version()) throw new Error("Compiled LDK library and LDK class files do not match"); // Fetching the LDK versions from C also checks that the header and binaries match const c_bindings_ver = wasm.TS_get_ldk_c_bindings_version(); const ldk_ver = wasm.TS_get_ldk_version(); if (c_bindings_ver == 0) throw new Error("LDK version did not match the header we built against"); if (ldk_ver == 0) throw new Error("LDK C bindings version did not match the header we built against"); const c_bindings_version = decodeString(c_bindings_ver); const ldk_version = decodeString(ldk_ver); console.log("Loaded LDK-Java Bindings with LDK " + ldk_version + " and LDK-C-Bindings " + c_bindings_version); isWasmInitialized = true; } const fn_list = ["uuuuuu", "buuuuu", "bbuuuu", "bbbuuu", "bbbbuu", "bbbbbu", "bbbbbb", "ubuubu", "ubuuuu", "ubbuuu", "uubuuu", "uubbuu", "uububu", "ububuu", "uuuubu"]; /* @internal */ export async function initializeWasmFromUint8Array(wasmBinary) { for (const fn of fn_list) { imports.env["js_invoke_function_" + fn] = js_invoke; } const { instance: wasmInstance } = await WebAssembly.instantiate(wasmBinary, imports); await finishInitializeWasm(wasmInstance); } /* @internal */ export async function initializeWasmFetch(uri) { for (const fn of fn_list) { imports.env["js_invoke_function_" + fn] = js_invoke; } const stream = fetch(uri); const { instance: wasmInstance } = await WebAssembly.instantiateStreaming(stream, imports); await finishInitializeWasm(wasmInstance); } // WASM CODEC /* @internal */ export function uint5ArrToBytes(inputArray) { const arr = new Uint8Array(inputArray.length); for (var i = 0; i < inputArray.length; i++) { arr[i] = inputArray[i].getVal(); } return arr; } /* @internal */ export function WitnessVersionArrToBytes(inputArray) { const arr = new Uint8Array(inputArray.length); for (var i = 0; i < inputArray.length; i++) { arr[i] = inputArray[i].getVal(); } return arr; } /* @internal */ export function encodeUint128(inputVal) { if (inputVal >= 0x10000000000000000000000000000000n) throw "U128s cannot exceed 128 bits"; const cArrayPointer = wasm.TS_malloc(16 + 8); const arrayLengthView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, 1); arrayLengthView[0] = BigInt(16); const arrayMemoryView = new Uint8Array(wasm.memory.buffer, cArrayPointer + 8, 16); for (var i = 0; i < 16; i++) arrayMemoryView[i] = Number((inputVal >> BigInt(i) * 8n) & 0xffn); return cArrayPointer; } /* @internal */ export function encodeUint8Array(inputArray) { if (inputArray == null) return 0; const cArrayPointer = wasm.TS_malloc(inputArray.length + 8); const arrayLengthView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, 1); arrayLengthView[0] = BigInt(inputArray.length); const arrayMemoryView = new Uint8Array(wasm.memory.buffer, cArrayPointer + 8, inputArray.length); arrayMemoryView.set(inputArray); return cArrayPointer; } /* @internal */ export function encodeUint16Array(inputArray) { if (inputArray == null) return 0; const cArrayPointer = wasm.TS_malloc((inputArray.length + 4) * 2); const arrayLengthView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, 1); arrayLengthView[0] = BigInt(inputArray.length); const arrayMemoryView = new Uint16Array(wasm.memory.buffer, cArrayPointer + 8, inputArray.length); arrayMemoryView.set(inputArray); return cArrayPointer; } /* @internal */ export function encodeUint32Array(inputArray) { if (inputArray == null) return 0; const cArrayPointer = wasm.TS_malloc((inputArray.length + 2) * 4); const arrayLengthView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, 1); arrayLengthView[0] = BigInt(inputArray.length); const arrayMemoryView = new Uint32Array(wasm.memory.buffer, cArrayPointer + 8, inputArray.length); arrayMemoryView.set(inputArray); return cArrayPointer; } /* @internal */ export function encodeUint64Array(inputArray) { if (inputArray == null) return 0; const cArrayPointer = wasm.TS_malloc((inputArray.length + 1) * 8); const arrayMemoryView = new BigUint64Array(wasm.memory.buffer, cArrayPointer, inputArray.length + 1); arrayMemoryView[0] = BigInt(inputArray.length); arrayMemoryView.set(inputArray, 1); return cArrayPointer; } /* @internal */ export function encodeInt64Array(inputArray) { if (inputArray == null) return 0; const cArrayPointer = wasm.TS_malloc((inputArray.length + 1) * 8); const arrayMemoryView = new BigInt64Array(wasm.memory.buffer, cArrayPointer, inputArray.length + 1); arrayMemoryView[0] = BigInt(inputArray.length); arrayMemoryView.set(inputArray, 1); return cArrayPointer; } /* @internal */ export function check_arr_len(arr, len) { if (arr !== null && arr.length != len) { throw new Error("Expected array of length " + len + " got " + arr.length); } return arr; } /* @internal */ export function check_16_arr_len(arr, len) { if (arr !== null && arr.length != len) { throw new Error("Expected array of length " + len + " got " + arr.length); } return arr; } /* @internal */ export function getArrayLength(arrayPointer) { const arraySizeViewer = new BigUint64Array(wasm.memory.buffer, arrayPointer, 1); const len = arraySizeViewer[0]; if (len >= (2n ** 32n)) throw new Error("Bogus Array Size"); return Number(len % (2n ** 32n)); } /* @internal */ export function decodeUint128(arrayPointer, free = true) { const arraySize = getArrayLength(arrayPointer); if (arraySize != 16) throw "Need 16 bytes for a uint128"; const actualArrayViewer = new Uint8Array(wasm.memory.buffer, arrayPointer + 8, arraySize); var val = 0n; for (var i = 0; i < 16; i++) { val <<= 8n; val |= BigInt(actualArrayViewer[i]); } if (free) { wasm.TS_free(arrayPointer); } return val; } /* @internal */ export function decodeUint8Array(arrayPointer, free = true) { const arraySize = getArrayLength(arrayPointer); const actualArrayViewer = new Uint8Array(wasm.memory.buffer, arrayPointer + 8, arraySize); // Clone the contents, TODO: In the future we should wrap the Viewer in a class that // will free the underlying memory when it becomes unreachable instead of copying here. // Note that doing so may have edge-case interactions with memory resizing (invalidating the buffer). const actualArray = actualArrayViewer.slice(0, arraySize); if (free) { wasm.TS_free(arrayPointer); } return actualArray; } /* @internal */ export function decodeUint16Array(arrayPointer, free = true) { const arraySize = getArrayLength(arrayPointer); const actualArrayViewer = new Uint16Array(wasm.memory.buffer, arrayPointer + 8, arraySize); // Clone the contents, TODO: In the future we should wrap the Viewer in a class that // will free the underlying memory when it becomes unreachable instead of copying here. // Note that doing so may have edge-case interactions with memory resizing (invalidating the buffer). const actualArray = actualArrayViewer.slice(0, arraySize); if (free) { wasm.TS_free(arrayPointer); } return actualArray; } /* @internal */ export function decodeUint64Array(arrayPointer, free = true) { const arraySize = getArrayLength(arrayPointer); const actualArrayViewer = new BigUint64Array(wasm.memory.buffer, // value arrayPointer + 8, // offset (ignoring length bytes) arraySize // uint32 count ); // Clone the contents, TODO: In the future we should wrap the Viewer in a class that // will free the underlying memory when it becomes unreachable instead of copying here. const actualArray = actualArrayViewer.slice(0, arraySize); if (free) { wasm.TS_free(arrayPointer); } return actualArray; } /* @internal */ export function decodeInt64Array(arrayPointer, free = true) { const arraySize = getArrayLength(arrayPointer); const actualArrayViewer = new BigInt64Array(wasm.memory.buffer, // value arrayPointer + 8, // offset (ignoring length bytes) arraySize // uint32 count ); // Clone the contents, TODO: In the future we should wrap the Viewer in a class that // will free the underlying memory when it becomes unreachable instead of copying here. const actualArray = actualArrayViewer.slice(0, arraySize); if (free) { wasm.TS_free(arrayPointer); } return actualArray; } export function freeWasmMemory(pointer) { wasm.TS_free(pointer); } /* @internal */ export function getU64ArrayElem(arrayPointer, idx) { const actualArrayViewer = new BigUint64Array(wasm.memory.buffer, arrayPointer + 8, idx + 1); return actualArrayViewer[idx]; } /* @internal */ export function getU32ArrayElem(arrayPointer, idx) { const actualArrayViewer = new Uint32Array(wasm.memory.buffer, arrayPointer + 8, idx + 1); return actualArrayViewer[idx]; } /* @internal */ export function getU8ArrayElem(arrayPointer, idx) { const actualArrayViewer = new Uint8Array(wasm.memory.buffer, arrayPointer + 8, idx + 1); return actualArrayViewer[idx]; } /* @internal */ export function encodeString(str) { const charArray = new TextEncoder().encode(str); return encodeUint8Array(charArray); } /* @internal */ export function decodeString(stringPointer, free = true) { const arraySize = getArrayLength(stringPointer); const memoryView = new Uint8Array(wasm.memory.buffer, stringPointer + 8, arraySize); const result = new TextDecoder("utf-8").decode(memoryView); if (free) { wasm.TS_free(stringPointer); } return result; } /* @internal */ export function getRemainingAllocationCount() { return 0; } /* @internal */ export function debugPrintRemainingAllocs() { } /** * Indicates whether the balance is derived from a cooperative close, a force-close * (for holder or counterparty), or whether it is for an HTLC. */ export var BalanceSource; (function (BalanceSource) { /** * The channel was force closed by the holder. */ BalanceSource[BalanceSource["LDKBalanceSource_HolderForceClosed"] = 0] = "LDKBalanceSource_HolderForceClosed"; /** * The channel was force closed by the counterparty. */ BalanceSource[BalanceSource["LDKBalanceSource_CounterpartyForceClosed"] = 1] = "LDKBalanceSource_CounterpartyForceClosed"; /** * The channel was cooperatively closed. */ BalanceSource[BalanceSource["LDKBalanceSource_CoopClose"] = 2] = "LDKBalanceSource_CoopClose"; /** * This balance is the result of an HTLC. */ BalanceSource[BalanceSource["LDKBalanceSource_Htlc"] = 3] = "LDKBalanceSource_Htlc"; })(BalanceSource || (BalanceSource = {})); /** * Whether this blinded HTLC is being failed backwards by the introduction node or a blinded node, * which determines the failure message that should be used. */ export var BlindedFailure; (function (BlindedFailure) { /** * This HTLC is being failed backwards by the introduction node, and thus should be failed with [`msgs::UpdateFailHTLC`] and error code `0x8000|0x4000|24`. */ BlindedFailure[BlindedFailure["LDKBlindedFailure_FromIntroductionNode"] = 0] = "LDKBlindedFailure_FromIntroductionNode"; /** * This HTLC is being failed backwards by a blinded node within the path, and thus should be failed with [`msgs::UpdateFailMalformedHTLC`] and error code `0x8000|0x4000|24`. */ BlindedFailure[BlindedFailure["LDKBlindedFailure_FromBlindedNode"] = 1] = "LDKBlindedFailure_FromBlindedNode"; })(BlindedFailure || (BlindedFailure = {})); /** * Errors that may occur when converting a [`RawBolt11Invoice`] to a [`Bolt11Invoice`]. They relate to * the requirements sections in BOLT #11 */ export var Bolt11SemanticError; (function (Bolt11SemanticError) { /** * The invoice is missing the mandatory payment hash */ Bolt11SemanticError[Bolt11SemanticError["LDKBolt11SemanticError_NoPaymentHash"] = 0] = "LDKBolt11SemanticError_NoPaymentHash"; /** * The invoice has multiple payment hashes which isn't allowed */ Bolt11SemanticError[Bolt11SemanticError["LDKBolt11SemanticError_MultiplePaymentHashes"] = 1] = "LDKBolt11SemanticError_MultiplePaymentHashes"; /** * No description or description hash are part of the invoice */ Bolt11SemanticError[Bolt11SemanticError["LDKBolt11SemanticError_NoDescription"] = 2] = "LDKBolt11SemanticError_NoDescription"; /** * The invoice contains multiple descriptions and/or description hashes which isn't allowed */ Bolt11SemanticError[Bolt11SemanticError["LDKBolt11SemanticError_MultipleDescriptions"] = 3] = "LDKBolt11SemanticError_MultipleDescriptions"; /** * The invoice is missing the mandatory payment secret, which all modern lightning nodes should provide. */ Bolt11SemanticError[Bolt11SemanticError["LDKBolt11SemanticError_NoPaymentSecret"] = 4] = "LDKBolt11SemanticError_NoPaymentSecret"; /** * The invoice contains multiple payment secrets */ Bolt11SemanticError[Bolt11SemanticError["LDKBolt11SemanticError_MultiplePaymentSecrets"] = 5] = "LDKBolt11SemanticError_MultiplePaymentSecrets"; /** * The invoice's features are invalid */ Bolt11SemanticError[Bolt11SemanticError["LDKBolt11SemanticError_InvalidFeatures"] = 6] = "LDKBolt11SemanticError_InvalidFeatures"; /** * The recovery id doesn't fit the signature/pub key */ Bolt11SemanticError[Bolt11SemanticError["LDKBolt11SemanticError_InvalidRecoveryId"] = 7] = "LDKBolt11SemanticError_InvalidRecoveryId"; /** * The invoice's signature is invalid */ Bolt11SemanticError[Bolt11SemanticError["LDKBolt11SemanticError_InvalidSignature"] = 8] = "LDKBolt11SemanticError_InvalidSignature"; /** * The invoice's amount was not a whole number of millisatoshis */ Bolt11SemanticError[Bolt11SemanticError["LDKBolt11SemanticError_ImpreciseAmount"] = 9] = "LDKBolt11SemanticError_ImpreciseAmount"; })(Bolt11SemanticError || (Bolt11SemanticError = {})); /** * Error when interpreting a TLV stream as a specific type. */ export var Bolt12SemanticError; (function (Bolt12SemanticError) { /** * The current system time is past the offer or invoice's expiration. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_AlreadyExpired"] = 0] = "LDKBolt12SemanticError_AlreadyExpired"; /** * The provided chain hash does not correspond to a supported chain. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnsupportedChain"] = 1] = "LDKBolt12SemanticError_UnsupportedChain"; /** * A chain was provided but was not expected. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnexpectedChain"] = 2] = "LDKBolt12SemanticError_UnexpectedChain"; /** * An amount was expected but was missing. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_MissingAmount"] = 3] = "LDKBolt12SemanticError_MissingAmount"; /** * The amount exceeded the total bitcoin supply or didn't match an expected amount. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_InvalidAmount"] = 4] = "LDKBolt12SemanticError_InvalidAmount"; /** * An amount was provided but was not sufficient in value. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_InsufficientAmount"] = 5] = "LDKBolt12SemanticError_InsufficientAmount"; /** * An amount was provided but was not expected. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnexpectedAmount"] = 6] = "LDKBolt12SemanticError_UnexpectedAmount"; /** * A currency was provided that is not supported. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnsupportedCurrency"] = 7] = "LDKBolt12SemanticError_UnsupportedCurrency"; /** * A feature was required but is unknown. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnknownRequiredFeatures"] = 8] = "LDKBolt12SemanticError_UnknownRequiredFeatures"; /** * Features were provided but were not expected. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnexpectedFeatures"] = 9] = "LDKBolt12SemanticError_UnexpectedFeatures"; /** * A required description was not provided. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_MissingDescription"] = 10] = "LDKBolt12SemanticError_MissingDescription"; /** * An issuer's signing pubkey was not provided. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_MissingIssuerSigningPubkey"] = 11] = "LDKBolt12SemanticError_MissingIssuerSigningPubkey"; /** * An issuer's signing pubkey was provided but was not expected. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnexpectedIssuerSigningPubkey"] = 12] = "LDKBolt12SemanticError_UnexpectedIssuerSigningPubkey"; /** * A quantity was expected but was missing. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_MissingQuantity"] = 13] = "LDKBolt12SemanticError_MissingQuantity"; /** * An unsupported quantity was provided. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_InvalidQuantity"] = 14] = "LDKBolt12SemanticError_InvalidQuantity"; /** * A quantity or quantity bounds was provided but was not expected. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnexpectedQuantity"] = 15] = "LDKBolt12SemanticError_UnexpectedQuantity"; /** * Metadata could not be used to verify the offers message. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_InvalidMetadata"] = 16] = "LDKBolt12SemanticError_InvalidMetadata"; /** * Metadata was provided but was not expected. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnexpectedMetadata"] = 17] = "LDKBolt12SemanticError_UnexpectedMetadata"; /** * Payer metadata was expected but was missing. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_MissingPayerMetadata"] = 18] = "LDKBolt12SemanticError_MissingPayerMetadata"; /** * A payer signing pubkey was expected but was missing. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_MissingPayerSigningPubkey"] = 19] = "LDKBolt12SemanticError_MissingPayerSigningPubkey"; /** * The payment id for a refund or request is already in use. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_DuplicatePaymentId"] = 20] = "LDKBolt12SemanticError_DuplicatePaymentId"; /** * Blinded paths were expected but were missing. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_MissingPaths"] = 21] = "LDKBolt12SemanticError_MissingPaths"; /** * Blinded paths were provided but were not expected. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnexpectedPaths"] = 22] = "LDKBolt12SemanticError_UnexpectedPaths"; /** * The blinded payinfo given does not match the number of blinded path hops. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_InvalidPayInfo"] = 23] = "LDKBolt12SemanticError_InvalidPayInfo"; /** * An invoice creation time was expected but was missing. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_MissingCreationTime"] = 24] = "LDKBolt12SemanticError_MissingCreationTime"; /** * An invoice payment hash was expected but was missing. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_MissingPaymentHash"] = 25] = "LDKBolt12SemanticError_MissingPaymentHash"; /** * An invoice payment hash was provided but was not expected. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnexpectedPaymentHash"] = 26] = "LDKBolt12SemanticError_UnexpectedPaymentHash"; /** * A signing pubkey was not provided. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_MissingSigningPubkey"] = 27] = "LDKBolt12SemanticError_MissingSigningPubkey"; /** * A signing pubkey was provided but a different one was expected. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_InvalidSigningPubkey"] = 28] = "LDKBolt12SemanticError_InvalidSigningPubkey"; /** * A signature was expected but was missing. */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_MissingSignature"] = 29] = "LDKBolt12SemanticError_MissingSignature"; /** * A Human Readable Name was provided but was not expected (i.e. was included in a [`Refund`]). [`Refund`]: super::refund::Refund */ Bolt12SemanticError[Bolt12SemanticError["LDKBolt12SemanticError_UnexpectedHumanReadableName"] = 30] = "LDKBolt12SemanticError_UnexpectedHumanReadableName"; })(Bolt12SemanticError || (Bolt12SemanticError = {})); /** * An enum which can either contain a or not */ export var COption_NoneZ; (function (COption_NoneZ) { /** * When we're in this state, this COption_NoneZ contains a */ COption_NoneZ[COption_NoneZ["LDKCOption_NoneZ_Some"] = 0] = "LDKCOption_NoneZ_Some"; /** * When we're in this state, this COption_NoneZ contains nothing */ COption_NoneZ[COption_NoneZ["LDKCOption_NoneZ_None"] = 1] = "LDKCOption_NoneZ_None"; })(COption_NoneZ || (COption_NoneZ = {})); /** * An enum representing the status of a channel monitor update persistence. * * These are generally used as the return value for an implementation of [`Persist`] which is used * as the storage layer for a [`ChainMonitor`]. See the docs on [`Persist`] for a high-level * explanation of how to handle different cases. * * While `UnrecoverableError` is provided as a failure variant, it is not truly \"handled\" on the * calling side, and generally results in an immediate panic. For those who prefer to avoid * panics, `InProgress` can be used and you can retry the update operation in the background or * shut down cleanly. * * Note that channels should generally *not* be force-closed after a persistence failure. * Force-closing with the latest [`ChannelMonitorUpdate`] applied may result in a transaction * being broadcast which can only be spent by the latest [`ChannelMonitor`]! Thus, if the * latest [`ChannelMonitor`] is not durably persisted anywhere and exists only in memory, naively * calling [`ChannelManager::force_close_broadcasting_latest_txn`] *may result in loss of funds*! * * [`Persist`]: chainmonitor::Persist * [`ChainMonitor`]: chainmonitor::ChainMonitor * [`ChannelManager::force_close_broadcasting_latest_txn`]: crate::ln::channelmanager::ChannelManager::force_close_broadcasting_latest_txn */ export var ChannelMonitorUpdateStatus; (function (ChannelMonitorUpdateStatus) { /** * The update has been durably persisted and all copies of the relevant [`ChannelMonitor`] have been updated. This includes performing any `fsync()` calls required to ensure the update is guaranteed to be available on restart even if the application crashes. */ ChannelMonitorUpdateStatus[ChannelMonitorUpdateStatus["LDKChannelMonitorUpdateStatus_Completed"] = 0] = "LDKChannelMonitorUpdateStatus_Completed"; /** * Indicates that the update will happen asynchronously in the background or that a transient failure occurred which is being retried in the background and will eventually complete. This will \"freeze\" a channel, preventing us from revoking old states or submitting a new commitment transaction to the counterparty. Once the update(s) which are `InProgress` have been completed, a [`MonitorEvent::Completed`] can be used to restore the channel to an operational state. Even when a channel has been \"frozen\", updates to the [`ChannelMonitor`] can continue to occur (e.g. if an inbound HTLC which we forwarded was claimed upstream, resulting in us attempting to claim it on this channel) and those updates must still be persisted. No updates to the channel will be made which could invalidate other [`ChannelMonitor`]s until a [`MonitorEvent::Completed`] is provided, even if you return no error on a later monitor update for the same channel. For deployments where a copy of [`ChannelMonitor`]s and other local state are backed up in a remote location (with local copies persisted immediately), it is anticipated that all updates will return [`InProgress`] until the remote copies could be updated. Note that while fully asynchronous persistence of [`ChannelMonitor`] data is generally reliable, this feature is considered beta, and a handful of edge-cases remain. Until the remaining cases are fixed, in rare cases, *using this feature may lead to funds loss*. [`InProgress`]: ChannelMonitorUpdateStatus::InProgress */ ChannelMonitorUpdateStatus[ChannelMonitorUpdateStatus["LDKChannelMonitorUpdateStatus_InProgress"] = 1] = "LDKChannelMonitorUpdateStatus_InProgress"; /** * Indicates that an update has failed and will not complete at any point in the future. Currently returning this variant will cause LDK to immediately panic to encourage immediate shutdown. In the future this may be updated to disconnect peers and refuse to continue normal operation without a panic. Applications which wish to perform an orderly shutdown after failure should consider returning [`InProgress`] instead and simply shut down without ever marking the update complete. [`InProgress`]: ChannelMonitorUpdateStatus::InProgress */ ChannelMonitorUpdateStatus[ChannelMonitorUpdateStatus["LDKChannelMonitorUpdateStatus_UnrecoverableError"] = 2] = "LDKChannelMonitorUpdateStatus_UnrecoverableError"; })(ChannelMonitorUpdateStatus || (ChannelMonitorUpdateStatus = {})); /** * Further information on the details of the channel shutdown. * Upon channels being forced closed (i.e. commitment transaction confirmation detected * by `ChainMonitor`), ChannelShutdownState will be set to `ShutdownComplete` or * the channel will be removed shortly. * Also note, that in normal operation, peers could disconnect at any of these states * and require peer re-connection before making progress onto other states */ export var ChannelShutdownState; (function (ChannelShutdownState) { /** * Channel has not sent or received a shutdown message. */ ChannelShutdownState[ChannelShutdownState["LDKChannelShutdownState_NotShuttingDown"] = 0] = "LDKChannelShutdownState_NotShuttingDown"; /** * Local node has sent a shutdown message for this channel. */ ChannelShutdownState[ChannelShutdownState["LDKChannelShutdownState_ShutdownInitiated"] = 1] = "LDKChannelShutdownState_ShutdownInitiated"; /** * Shutdown message exchanges have concluded and the channels are in the midst of resolving all existing open HTLCs before closing can continue. */ ChannelShutdownState[ChannelShutdownState["LDKChannelShutdownState_ResolvingHTLCs"] = 2] = "LDKChannelShutdownState_ResolvingHTLCs"; /** * All HTLCs have been resolved, nodes are currently negotiating channel close onchain fee rates. */ ChannelShutdownState[ChannelShutdownState["LDKChannelShutdownState_NegotiatingClosingFee"] = 3] = "LDKChannelShutdownState_NegotiatingClosingFee"; /** * We've successfully negotiated a closing_signed dance. At this point `ChannelManager` is about to drop the channel. */ ChannelShutdownState[ChannelShutdownState["LDKChannelShutdownState_ShutdownComplete"] = 4] = "LDKChannelShutdownState_ShutdownComplete"; })(ChannelShutdownState || (ChannelShutdownState = {})); /** * An enum that represents the priority at which we want a transaction to confirm used for feerate * estimation. */ export var ConfirmationTarget; (function (ConfirmationTarget) { /** * The most aggressive (i.e. highest) feerate estimate available. This is used to sanity-check our counterparty's feerates and should be as conservative as possible to ensure that we don't confuse a peer using a very conservative estimator for one trying to burn channel balance to dust. */ ConfirmationTarget[ConfirmationTarget["LDKConfirmationTarget_MaximumFeeEstimate"] = 0] = "LDKConfirmationTarget_MaximumFeeEstimate"; /** * We have some funds available on chain which we need to spend prior to some expiry time at which point our counterparty may be able to steal them. Generally we have in the high tens to low hundreds of blocks to get our transaction on-chain (it doesn't have to happen in the next few blocks!), but we shouldn't risk too low a fee - this should be a relatively high priority feerate. */ ConfirmationTarget[ConfirmationTarget["LDKConfirmationTarget_UrgentOnChainSweep"] = 1] = "LDKConfirmationTarget_UrgentOnChainSweep"; /** * This is the lowest feerate we will allow our channel counterparty to have in an anchor channel in order to close the channel if a channel party goes away. This needs to be sufficient to get into the mempool when the channel needs to be force-closed. Setting too high may result in force-closures if our counterparty attempts to use a lower feerate. Because this is for anchor channels, we can always bump the feerate later; the feerate here only needs to be sufficient to enter the mempool. A good estimate is the expected mempool minimum at the time of force-closure. Obviously this is not an estimate which is very easy to calculate because we do not know the future. Using a simple long-term fee estimate or tracking of the mempool minimum is a good approach to ensure you can always close the channel. A future change to Bitcoin's P2P network (package relay) may obviate the need for this entirely. */ ConfirmationTarget[ConfirmationTarget["LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee"] = 2] = "LDKConfirmationTarget_MinAllowedAnchorChannelRemoteFee"; /** * The lowest feerate we will allow our channel counterparty to have in a non-anchor channel. This is the feerate on the transaction which we (or our counterparty) will broadcast in order to close the channel if a channel party goes away. Setting this value too high will cause immediate force-closures in order to avoid having an unbroadcastable state. This feerate represents the fee we pick now, which must be sufficient to enter a block at an arbitrary time in the future. Obviously this is not an estimate which is very easy to calculate. This can leave channels subject to being unable to close if feerates rise, and in general you should prefer anchor channels to ensure you can increase the feerate when the transactions need broadcasting. Do note some fee estimators round up to the next full sat/vbyte (ie 250 sats per kw), causing occasional issues with feerate disagreements between an initiator that wants a feerate of 1.1 sat/vbyte and a receiver that wants 1.1 rounded up to 2. If your fee estimator rounds subtracting 250 to your desired feerate here can help avoid this issue. [`ChannelConfig::max_dust_htlc_exposure`]: crate::util::config::ChannelConfig::max_dust_htlc_exposure */ ConfirmationTarget[ConfirmationTarget["LDKConfirmationTarget_MinAllowedNonAnchorChannelRemoteFee"] = 3] = "LDKConfirmationTarget_MinAllowedNonAnchorChannelRemoteFee"; /** * This is the feerate on the transaction which we (or our counterparty) will broadcast in order to close the channel if a channel party goes away. This needs to be sufficient to get into the mempool when the channel needs to be force-closed. Setting too low may result in force-closures. Because this is for anchor channels, it can be a low value as we can always bump the feerate later. A good estimate is the expected mempool minimum at the time of force-closure. Obviously this is not an estimate which is very easy to calculate because we do not know the future. Using a simple long-term fee estimate or tracking of the mempool minimum is a good approach to ensure you can always close the channel. A future change to Bitcoin's P2P network (package relay) may obviate the need for this entirely. */ ConfirmationTarget[ConfirmationTarget["LDKConfirmationTarget_AnchorChannelFee"] = 4] = "LDKConfirmationTarget_AnchorChannelFee"; /** * Lightning is built around the ability to broadcast a transaction in the future to close our channel and claim all pending funds. In order to do so, non-anchor channels are built with transactions which we need to be able to broadcast at some point in the future. This feerate represents the fee we pick now, which must be sufficient to enter a block at an arbitrary time in the future. Obviously this is not an estimate which is very easy to calculate, so most lightning nodes use some relatively high-priority feerate using the current mempool. This leaves channels subject to being unable to close if feerates rise, and in general you should prefer anchor channels to ensure you can increase the feerate when the transactions need broadcasting. Since this should represent the feerate of a channel close that does not need fee bumping, this is also used as an upper bound for our attempted feerate when doing cooperative closure of any channel. */ ConfirmationTarget[ConfirmationTarget["LDKConfirmationTarget_NonAnchorChannelFee"] = 5] = "LDKConfirmationTarget_NonAnchorChannelFee"; /** * When cooperatively closing a channel, this is the minimum feerate we will accept. Recommended at least within a day or so worth of blocks. This will also be used when initiating a cooperative close of a channel. When closing a channel you can override this fee by using [`ChannelManager::close_channel_with_feerate_and_script`]. [`ChannelManager::close_channel_with_feerate_and_script`]: crate::ln::channelmanager::ChannelManager::close_channel_with_feerate_and_script */ ConfirmationTarget[ConfirmationTarget["LDKConfirmationTarget_ChannelCloseMinimum"] = 6] = "LDKConfirmationTarget_ChannelCloseMinimum"; /** * The feerate used to claim on-chain funds when there is no particular urgency to do so. It is used to get commitment transactions without any HTLCs confirmed in [`ChannelMonitor`] and by [`OutputSweeper`] on transactions spending [`SpendableOutputDescriptor`]s after a channel closure. Generally spending these outputs is safe as long as they eventually confirm, so a value (slightly above) the mempool minimum should suffice. However, as this value will influence how long funds will be unavailable after channel closure, [`FeeEstimator`] implementors might want to choose a higher feerate to regain control over funds faster. [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor [`OutputSweeper`]: crate::util::sweep::OutputSweeper [`SpendableOutputDescriptor`]: crate::sign::SpendableOutputDescriptor */ ConfirmationTarget[ConfirmationTarget["LDKConfirmationTarget_OutputSpendingFee"] = 7] = "LDKConfirmationTarget_OutputSpendingFee"; })(ConfirmationTarget || (ConfirmationTarget = {})); /** * Errors that may occur when constructing a new [`RawBolt11Invoice`] or [`Bolt11Invoice`] */ export var CreationError; (function (CreationError) { /** * The supplied description string was longer than 639 __bytes__ (see [`Description::new`]) */ CreationError[CreationError["LDKCreationError_DescriptionTooLong"] = 0] = "LDKCreationError_DescriptionTooLong"; /** * The specified route has too many hops and can't be encoded */ CreationError[CreationError["LDKCreationError_RouteTooLong"] = 1] = "LDKCreationError_RouteTooLong"; /** * The Unix timestamp of the supplied date is less than zero or greater than 35-bits */ CreationError[CreationError["LDKCreationError_TimestampOutOfBounds"] = 2] = "LDKCreationError_TimestampOutOfBounds"; /** * The supplied millisatoshi amount was greater than the total bitcoin supply. */ CreationError[CreationError["LDKCreationError_InvalidAmount"] = 3] = "LDKCreationError_InvalidAmount"; /** * Route hints were required for this invoice and were missing. */ CreationError[CreationError["LDKCreationError_MissingRouteHints"] = 4] = "LDKCreationError_MissingRouteHints"; /** * The provided `min_final_cltv_expiry_delta` was less than rust-lightning's minimum. */ CreationError[CreationError["LDKCreationError_MinFinalCltvExpiryDeltaTooShort"] = 5] = "LDKCreationError_MinFinalCltvExpiryDeltaTooShort"; })(CreationError || (CreationError = {})); /** * Enum representing the crypto currencies (or networks) supported by this library */ export var Currency; (function (Currency) { /** * Bitcoin mainnet */ Currency[Currency["LDKCurrency_Bitcoin"] = 0] = "LDKCurrency_Bitcoin"; /** * Bitcoin testnet */ Currency[Currency["LDKCurrency_BitcoinTestnet"] = 1] = "LDKCurrency_BitcoinTestnet"; /** * Bitcoin regtest */ Currency[Currency["LDKCurrency_Regtest"] = 2] = "LDKCurrency_Regtest"; /** * Bitcoin simnet */ Currency[Currency["LDKCurrency_Simnet"] = 3] = "LDKCurrency_Simnet"; /** * Bitcoin signet */ Currency[Currency["LDKCurrency_Signet"] = 4] = "LDKCurrency_Signet"; })(Currency || (Currency = {})); /** * The side of a channel that is the [`IntroductionNode`] in a blinded path. [BOLT 7] defines which * nodes is which in the [`ChannelAnnouncement`] message. * * [BOLT 7]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_announcement-message * [`ChannelAnnouncement`]: crate::ln::msgs::ChannelAnnouncement */ export var Direction; (function (Direction) { /** * The lesser node id when compared lexicographically in ascending order. */ Direction[Direction["LDKDirection_NodeOne"] = 0] = "LDKDirection_NodeOne"; /** * The greater node id when compared lexicographically in ascending order. */ Direction[Direction["LDKDirection_NodeTwo"] = 1] = "LDKDirection_NodeTwo"; })(Direction || (Direction = {})); /** * Describes the type of HTLC claim as determined by analyzing the witness. */ export var HTLCClaim; (function (HTLCClaim) { /** * Claims an offered output on a commitment transaction through the timeout path. */ HTLCClaim[HTLCClaim["LDKHTLCClaim_OfferedTimeout"] = 0] = "LDKHTLCClaim_OfferedTimeout"; /** * Claims an offered output on a commitment transaction through the success path. */ HTLCClaim[HTLCClaim["LDKHTLCClaim_OfferedPreimage"] = 1] = "LDKHTLCClaim_OfferedPreimage"; /** * Claims an accepted output on a commitment transaction through the timeout path. */ HTLCClaim[HTLCClaim["LDKHTLCClaim_AcceptedTimeout"] = 2] = "LDKHTLCClaim_AcceptedTimeout"; /** * Claims an accepted output on a commitment transaction through the success path. */ HTLCClaim[HTLCClaim["LDKHTLCClaim_AcceptedPreimage"] = 3] = "LDKHTLCClaim_AcceptedPreimage"; /** * Claims an offered/accepted output on a commitment transaction through the revocation path. */ HTLCClaim[HTLCClaim["LDKHTLCClaim_Revocation"] = 4] = "LDKHTLCClaim_Revocation"; })(HTLCClaim || (HTLCClaim = {})); /** * Represents an IO Error. Note that some information is lost in the conversion from Rust. */ export var IOError; (function (IOError) { IOError[IOError["LDKIOError_NotFound"] = 0] = "LDKIOError_NotFound"; IOError[IOError["LDKIOError_PermissionDenied"] = 1] = "LDKIOError_PermissionDenied"; IOError[IOError["LDKIOError_ConnectionRefused"] = 2] = "LDKIOError_ConnectionRefused"; IOError[IOError["LDKIOError_ConnectionReset"] = 3] = "LDKIOError_ConnectionReset"; IOError[IOError["LDKIOError_ConnectionAborted"] = 4] = "LDKIOError_ConnectionAborted"; IOError[IOError["LDKIOError_NotConnected"] = 5] = "LDKIOError_NotConnected"; IOError[IOError["LDKIOError_AddrInUse"] = 6] = "LDKIOError_AddrInUse"; IOError[IOError["LDKIOError_AddrNotAvailable"] = 7] = "LDKIOError_AddrNotAvailable"; IOError[IOError["LDKIOError_BrokenPipe"] = 8] = "LDKIOError_BrokenPipe"; IOError[IOError["LDKIOError_AlreadyExists"] = 9] = "LDKIOError_AlreadyExists"; IOError[IOError["LDKIOError_WouldBlock"] = 10] = "LDKIOError_WouldBlock"; IOError[IOError["LDKIOError_InvalidInput"] = 11] = "LDKIOError_InvalidInput"; IOError[IOError["LDKIOError_InvalidData"] = 12] = "LDKIOError_InvalidData"; IOError[IOError["LDKIOError_TimedOut"] = 13] = "LDKIOError_TimedOut"; IOError[IOError["LDKIOError_WriteZero"] = 14] = "LDKIOError_WriteZero"; IOError[IOError["LDKIOError_Interrupted"] = 15] = "LDKIOError_Interrupted"; IOError[IOError["LDKIOError_Other"] = 16] = "LDKIOError_Other"; IOError[IOError["LDKIOError_UnexpectedEof"] = 17] = "LDKIOError_UnexpectedEof"; })(IOError || (IOError = {})); /** * Exposes the state of pending inbound HTLCs. * * At a high level, an HTLC being forwarded from one Lightning node to another Lightning node goes * through the following states in the state machine: * - Announced for addition by the originating node through the update_add_htlc message. * - Added to the commitment transaction of the receiving node and originating node in turn * through the exchange of commitment_signed and revoke_and_ack messages. * - Announced for resolution (fulfillment or failure) by the receiving node through either one of * the update_fulfill_htlc, update_fail_htlc, and update_fail_malformed_htlc messages. * - Removed from the commitment transaction of the originating node and receiving node in turn * through the exchange of commitment_signed and revoke_and_ack messages. * * This can be used to inspect what next message an HTLC is waiting for to advance its state. */ export var InboundHTLCStateDetails; (function (InboundHTLCStateDetails) { /** * We have added this HTLC in our commitment transaction by receiving commitment_signed and returning revoke_and_ack. We are awaiting the appropriate revoke_and_ack's from the remote before this HTLC is included on the remote commitment transaction. */ InboundHTLCStateDetails[InboundHTLCStateDetails["LDKInboundHTLCStateDetails_AwaitingRemoteRevokeToAdd"] = 0] = "LDKInboundHTLCStateDetails_AwaitingRemoteRevokeToAdd"; /** * This HTLC has been included in the commitment_signed and revoke_and_ack messages on both sides and is included in both commitment transactions. This HTLC is now safe to either forward or be claimed as a payment by us. The HTLC will remain in this state until the forwarded upstream HTLC has been resolved and we resolve this HTLC correspondingly, or until we claim it as a payment. If it is part of a multipart payment, it will only be claimed together with other required parts. */ InboundHTLCStateDetails[InboundHTLCStateDetails["LDKInboundHTLCStateDetails_Committed"] = 1] = "LDKInboundHTLCStateDetails_Committed"; /** * We have received the preimage for this HTLC and it is being removed by fulfilling it with update_fulfill_htlc. This HTLC is still on both commitment transactions, but we are awaiting the appropriate revoke_and_ack's from the remote before this HTLC is removed from the remote commitment transaction after update_fulfill_htlc. */ InboundHTLCStateDetails[InboundHTLCStateDetails["LDKInboundHTLCStateDetails_AwaitingRemoteRevokeToRemoveFulfill"] = 2] = "LDKInboundHTLCStateDetails_AwaitingRemoteRevokeToRemoveFulfill"; /** * The HTLC is being removed by failing it with update_fail_htlc or update_fail_malformed_htlc. This HTLC is still on both commitment transactions, but we are awaiting the appropriate revoke_and_ack's from the remote before this HTLC is removed from the remote commitment transaction. */ InboundHTLCStateDetails[InboundHTLCStateDetails["LDKInboundHTLCStateDetails_AwaitingRemoteRevokeToRemoveFail"] = 3] = "LDKInboundHTLCStateDetails_AwaitingRemoteRevokeToRemoveFail"; })(InboundHTLCStateDetails || (InboundHTLCStateDetails = {})); /** * An object representing the status of an order. */ export var LSPS1OrderState; (function (LSPS1OrderState) { /** * The order has been created. */ LSPS1OrderState[LSPS1OrderState["LDKLSPS1OrderState_Created"] = 0] = "LDKLSPS1OrderState_Created"; /** * The LSP has opened the channel and published the funding transaction. */ LSPS1OrderState[LSPS1OrderState["LDKLSPS1OrderState_Completed"] = 1] = "LDKLSPS1OrderState_Completed"; /** * The order failed. */ LSPS1OrderState[LSPS1OrderState["LDKLSPS1OrderState_Failed"] = 2] = "LDKLSPS1OrderState_Failed"; })(LSPS1OrderState || (LSPS1OrderState = {})); /** * The state of a payment. * * Note*: Previously, the spec also knew a `CANCELLED` state for BOLT11 payments, which has since * been deprecated and `REFUNDED` should be used instead. */ export var LSPS1PaymentState; (function (LSPS1PaymentState) { /** * A payment is expected. */ LSPS1PaymentState[LSPS1PaymentState["LDKLSPS1PaymentState_ExpectPayment"] = 0] = "LDKLSPS1PaymentState_ExpectPayment"; /** * A sufficient payment has been received. */ LSPS1PaymentState[LSPS1PaymentState["LDKLSPS1PaymentState_Paid"] = 1] = "LDKLSPS1PaymentState_Paid"; /** * The payment has been refunded. */ LSPS1PaymentState[LSPS1PaymentState["LDKLSPS1PaymentState_Refunded"] = 2] = "LDKLSPS1PaymentState_Refunded"; })(LSPS1PaymentState || (LSPS1PaymentState = {})); /** * An enum representing the available verbosity levels of the logger. */ export var Level; (function (Level) { /** * Designates extremely verbose information, including gossip-induced messages */ Level[Level["LDKLevel_Gossip"] = 0] = "LDKLevel_Gossip"; /** * Designates very low priority, often extremely verbose, information */ Level[Level["LDKLevel_Trace"] = 1] = "LDKLevel_Trace"; /** * Designates lower priority information */ Level[Level["LDKLevel_Debug"] = 2