UNPKG

lightningdevkit

Version:
275 lines 11.3 kB
import { Option_u64Z } from '../structs/Option_u64Z.mjs'; import { BlindedMessagePath } from '../structs/BlindedMessagePath.mjs'; import { Option_CVec_u8ZZ } from '../structs/Option_CVec_u8ZZ.mjs'; import { HumanReadableName } from '../structs/HumanReadableName.mjs'; import { Option_AmountZ } from '../structs/Option_AmountZ.mjs'; import { Quantity } from '../structs/Quantity.mjs'; import { PrintableString } from '../structs/PrintableString.mjs'; import { OfferFeatures } from '../structs/OfferFeatures.mjs'; import { TaggedHash } from '../structs/TaggedHash.mjs'; import { InvoiceRequestFeatures } from '../structs/InvoiceRequestFeatures.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * A semantically valid [`InvoiceRequest`] that hasn't been signed. * * # Serialization * * This is serialized as a TLV stream, which includes TLV records from the originating message. As * such, it may include unknown, odd TLV records. */ export class UnsignedInvoiceRequest extends CommonBase { /* @internal */ constructor(_dummy, ptr) { super(ptr, bindings.UnsignedInvoiceRequest_free); } clone_ptr() { const ret = bindings.UnsignedInvoiceRequest_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the UnsignedInvoiceRequest */ clone() { const ret = bindings.UnsignedInvoiceRequest_clone(this.ptr); const ret_hu_conv = new UnsignedInvoiceRequest(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Returns the [`TaggedHash`] of the invoice to sign. */ tagged_hash() { const ret = bindings.UnsignedInvoiceRequest_tagged_hash(this.ptr); const ret_hu_conv = new TaggedHash(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * The chains that may be used when paying a requested invoice (e.g., bitcoin mainnet). * Payments must be denominated in units of the minimal lightning-payable unit (e.g., msats) * for the selected chain. */ chains() { const ret = bindings.UnsignedInvoiceRequest_chains(this.ptr); const ret_conv_12_len = bindings.getArrayLength(ret); const ret_conv_12_arr = new Array(ret_conv_12_len).fill(null); for (var m = 0; m < ret_conv_12_len; m++) { const ret_conv_12 = bindings.getU32ArrayElem(ret, m); const ret_conv_12_conv = bindings.decodeUint8Array(ret_conv_12); ret_conv_12_arr[m] = ret_conv_12_conv; } bindings.freeWasmMemory(ret); return ret_conv_12_arr; } /** * Opaque bytes set by the originator. Useful for authentication and validating fields since it * is reflected in `invoice_request` messages along with all the other fields from the `offer`. */ metadata() { const ret = bindings.UnsignedInvoiceRequest_metadata(this.ptr); const ret_hu_conv = Option_CVec_u8ZZ.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * The minimum amount required for a successful payment of a single item. */ amount() { const ret = bindings.UnsignedInvoiceRequest_amount(this.ptr); const ret_hu_conv = Option_AmountZ.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * A complete description of the purpose of the payment. Intended to be displayed to the user * but with the caveat that it has not been verified in any way. * * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None */ description() { const ret = bindings.UnsignedInvoiceRequest_description(this.ptr); const ret_hu_conv = new PrintableString(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Features pertaining to the offer. */ offer_features() { const ret = bindings.UnsignedInvoiceRequest_offer_features(this.ptr); const ret_hu_conv = new OfferFeatures(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Duration since the Unix epoch when an invoice should no longer be requested. * * If `None`, the offer does not expire. */ absolute_expiry() { const ret = bindings.UnsignedInvoiceRequest_absolute_expiry(this.ptr); const ret_hu_conv = Option_u64Z.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * The issuer of the offer, possibly beginning with `user@domain` or `domain`. Intended to be * displayed to the user but with the caveat that it has not been verified in any way. * * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None */ issuer() { const ret = bindings.UnsignedInvoiceRequest_issuer(this.ptr); const ret_hu_conv = new PrintableString(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Paths to the recipient originating from publicly reachable nodes. Blinded paths provide * recipient privacy by obfuscating its node id. */ paths() { const ret = bindings.UnsignedInvoiceRequest_paths(this.ptr); const ret_conv_20_len = bindings.getArrayLength(ret); const ret_conv_20_arr = new Array(ret_conv_20_len).fill(null); for (var u = 0; u < ret_conv_20_len; u++) { const ret_conv_20 = bindings.getU64ArrayElem(ret, u); const ret_conv_20_hu_conv = new BlindedMessagePath(null, ret_conv_20); CommonBase.add_ref_from(ret_conv_20_hu_conv, this); ret_conv_20_arr[u] = ret_conv_20_hu_conv; } bindings.freeWasmMemory(ret); return ret_conv_20_arr; } /** * The quantity of items supported. */ supported_quantity() { const ret = bindings.UnsignedInvoiceRequest_supported_quantity(this.ptr); const ret_hu_conv = Quantity.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * The public key corresponding to the key used by the recipient to sign invoices. * - If [`Offer::paths`] is empty, MUST be `Some` and contain the recipient's node id for * sending an [`InvoiceRequest`]. * - If [`Offer::paths`] is not empty, MAY be `Some` and contain a transient id. * - If `None`, the signing pubkey will be the final blinded node id from the * [`BlindedMessagePath`] in [`Offer::paths`] used to send the [`InvoiceRequest`]. * * See also [`Bolt12Invoice::signing_pubkey`]. * * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest * [`Bolt12Invoice::signing_pubkey`]: crate::offers::invoice::Bolt12Invoice::signing_pubkey * * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None */ issuer_signing_pubkey() { const ret = bindings.UnsignedInvoiceRequest_issuer_signing_pubkey(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * An unpredictable series of bytes, typically containing information about the derivation of * [`payer_signing_pubkey`]. * * [`payer_signing_pubkey`]: Self::payer_signing_pubkey */ payer_metadata() { const ret = bindings.UnsignedInvoiceRequest_payer_metadata(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * A chain from [`Offer::chains`] that the offer is valid for. */ chain() { const ret = bindings.UnsignedInvoiceRequest_chain(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * The amount to pay in msats (i.e., the minimum lightning-payable unit for [`chain`]), which * must be greater than or equal to [`Offer::amount`], converted if necessary. * * [`chain`]: Self::chain */ amount_msats() { const ret = bindings.UnsignedInvoiceRequest_amount_msats(this.ptr); const ret_hu_conv = Option_u64Z.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Returns whether an amount was set in the request; otherwise, if [`amount_msats`] is `Some` * then it was inferred from the [`Offer::amount`] and [`quantity`]. * * [`amount_msats`]: Self::amount_msats * [`quantity`]: Self::quantity */ has_amount_msats() { const ret = bindings.UnsignedInvoiceRequest_has_amount_msats(this.ptr); return ret; } /** * Features pertaining to requesting an invoice. */ invoice_request_features() { const ret = bindings.UnsignedInvoiceRequest_invoice_request_features(this.ptr); const ret_hu_conv = new InvoiceRequestFeatures(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * The quantity of the offer's item conforming to [`Offer::is_valid_quantity`]. */ quantity() { const ret = bindings.UnsignedInvoiceRequest_quantity(this.ptr); const ret_hu_conv = Option_u64Z.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * A possibly transient pubkey used to sign the invoice request. */ payer_signing_pubkey() { const ret = bindings.UnsignedInvoiceRequest_payer_signing_pubkey(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * A payer-provided note which will be seen by the recipient and reflected back in the invoice * response. * * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None */ payer_note() { const ret = bindings.UnsignedInvoiceRequest_payer_note(this.ptr); const ret_hu_conv = new PrintableString(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * If the [`Offer`] was sourced from a BIP 353 Human Readable Name, this should be set by the * builder to indicate the original [`HumanReadableName`] which was resolved. * * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None */ offer_from_hrn() { const ret = bindings.UnsignedInvoiceRequest_offer_from_hrn(this.ptr); const ret_hu_conv = new HumanReadableName(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Serialize the UnsignedInvoiceRequest object into a byte array which can be read by UnsignedInvoiceRequest_read */ write() { const ret = bindings.UnsignedInvoiceRequest_write(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } } //# sourceMappingURL=UnsignedInvoiceRequest.mjs.map