UNPKG

lightningdevkit

Version:
333 lines 15 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 { OfferId } from '../structs/OfferId.mjs'; import { Result_InvoiceWithExplicitSigningPubkeyBuilderBolt12SemanticErrorZ } from '../structs/Result_InvoiceWithExplicitSigningPubkeyBuilderBolt12SemanticErrorZ.mjs'; import { Result_InvoiceWithDerivedSigningPubkeyBuilderBolt12SemanticErrorZ } from '../structs/Result_InvoiceWithDerivedSigningPubkeyBuilderBolt12SemanticErrorZ.mjs'; import { InvoiceRequestFields } from '../structs/InvoiceRequestFields.mjs'; import { PrintableString } from '../structs/PrintableString.mjs'; import { OfferFeatures } from '../structs/OfferFeatures.mjs'; import { InvoiceRequestFeatures } from '../structs/InvoiceRequestFeatures.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * An [`InvoiceRequest`] that has been verified by [`InvoiceRequest::verify_using_metadata`] or * [`InvoiceRequest::verify_using_recipient_data`] and exposes different ways to respond depending * on whether the signing keys were derived. */ export class VerifiedInvoiceRequest extends CommonBase { /* @internal */ constructor(_dummy, ptr) { super(ptr, bindings.VerifiedInvoiceRequest_free); } /** * The identifier of the [`Offer`] for which the [`InvoiceRequest`] was made. */ get_offer_id() { const ret = bindings.VerifiedInvoiceRequest_get_offer_id(this.ptr); const ret_hu_conv = new OfferId(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * The identifier of the [`Offer`] for which the [`InvoiceRequest`] was made. */ set_offer_id(val) { bindings.VerifiedInvoiceRequest_set_offer_id(this.ptr, CommonBase.get_ptr_of(val)); } clone_ptr() { const ret = bindings.VerifiedInvoiceRequest_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the VerifiedInvoiceRequest */ clone() { const ret = bindings.VerifiedInvoiceRequest_clone(this.ptr); const ret_hu_conv = new VerifiedInvoiceRequest(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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_has_amount_msats(this.ptr); return ret; } /** * Features pertaining to requesting an invoice. */ invoice_request_features() { const ret = bindings.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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.VerifiedInvoiceRequest_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; } /** * Creates an [`InvoiceBuilder`] for the request with the given required fields. * * Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after * `created_at`, which is used to set [`Bolt12Invoice::created_at`]. * * The caller is expected to remember the preimage of `payment_hash` in order to claim a payment * for the invoice. * * The `payment_paths` parameter is useful for maintaining the payment recipient's privacy. It * must contain one or more elements ordered from most-preferred to least-preferred, if there's * a preference. Note, however, that any privacy is lost if a public node id was used for * [`Offer::issuer_signing_pubkey`]. * * Errors if the request contains unknown required features. * * # Note * * If the originating [`Offer`] was created using [`OfferBuilder::deriving_signing_pubkey`], * then first use [`InvoiceRequest::verify_using_metadata`] or * [`InvoiceRequest::verify_using_recipient_data`] and then [`VerifiedInvoiceRequest`] methods * instead. * * [`Bolt12Invoice::created_at`]: crate::offers::invoice::Bolt12Invoice::created_at * [`OfferBuilder::deriving_signing_pubkey`]: crate::offers::offer::OfferBuilder::deriving_signing_pubkey */ respond_with_no_std(payment_paths, payment_hash, created_at) { const ret = bindings.VerifiedInvoiceRequest_respond_with_no_std(this.ptr, bindings.encodeUint64Array(payment_paths.map(payment_paths_conv_20 => CommonBase.get_ptr_of(payment_paths_conv_20))), bindings.encodeUint8Array(payment_hash), created_at); const ret_hu_conv = Result_InvoiceWithExplicitSigningPubkeyBuilderBolt12SemanticErrorZ.constr_from_ptr(ret); return ret_hu_conv; } /** * Creates an [`InvoiceBuilder`] for the request using the given required fields and that uses * derived signing keys from the originating [`Offer`] to sign the [`Bolt12Invoice`]. Must use * the same [`ExpandedKey`] as the one used to create the offer. * * See [`InvoiceRequest::respond_with_no_std`] for further details. * * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice */ respond_using_derived_keys_no_std(payment_paths, payment_hash, created_at) { const ret = bindings.VerifiedInvoiceRequest_respond_using_derived_keys_no_std(this.ptr, bindings.encodeUint64Array(payment_paths.map(payment_paths_conv_20 => CommonBase.get_ptr_of(payment_paths_conv_20))), bindings.encodeUint8Array(payment_hash), created_at); const ret_hu_conv = Result_InvoiceWithDerivedSigningPubkeyBuilderBolt12SemanticErrorZ.constr_from_ptr(ret); return ret_hu_conv; } /** * Fetch the [`InvoiceRequestFields`] for this verified invoice. * * These are fields which we expect to be useful when receiving a payment for this invoice * request, and include the returned [`InvoiceRequestFields`] in the * [`PaymentContext::Bolt12Offer`]. * * [`PaymentContext::Bolt12Offer`]: crate::blinded_path::payment::PaymentContext::Bolt12Offer */ fields() { const ret = bindings.VerifiedInvoiceRequest_fields(this.ptr); const ret_hu_conv = new InvoiceRequestFields(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } } //# sourceMappingURL=VerifiedInvoiceRequest.mjs.map