lightningdevkit
Version:
Lightning Development Kit
318 lines • 11.5 kB
JavaScript
import { Result_NoneNoneZ } from '../structs/Result_NoneNoneZ.mjs';
import { Result_Bolt11InvoiceFeaturesDecodeErrorZ } from '../structs/Result_Bolt11InvoiceFeaturesDecodeErrorZ.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* Features used within an invoice.
*/
export class Bolt11InvoiceFeatures extends CommonBase {
/* @internal */
constructor(_dummy, ptr) {
super(ptr, bindings.Bolt11InvoiceFeatures_free);
}
/**
* Serialize the Bolt11InvoiceFeatures object into a byte array which can be read by Bolt11InvoiceFeatures_read
*/
write() {
const ret = bindings.Bolt11InvoiceFeatures_write(this.ptr);
const ret_conv = bindings.decodeUint8Array(ret);
return ret_conv;
}
/**
* Read a Bolt11InvoiceFeatures from a byte array, created by Bolt11InvoiceFeatures_write
*/
static constructor_read(ser) {
const ret = bindings.Bolt11InvoiceFeatures_read(bindings.encodeUint8Array(ser));
const ret_hu_conv = Result_Bolt11InvoiceFeaturesDecodeErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Checks if two Bolt11InvoiceFeaturess contain equal inner contents.
* This ignores pointers and is_owned flags and looks at the values in fields.
* Two objects with NULL inner values will be considered "equal" here.
*/
eq(b) {
const ret = bindings.Bolt11InvoiceFeatures_eq(this.ptr, CommonBase.get_ptr_of(b));
CommonBase.add_ref_from(this, b);
return ret;
}
clone_ptr() {
const ret = bindings.Bolt11InvoiceFeatures_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the Bolt11InvoiceFeatures
*/
clone() {
const ret = bindings.Bolt11InvoiceFeatures_clone(this.ptr);
const ret_hu_conv = new Bolt11InvoiceFeatures(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Generates a non-cryptographic 64-bit hash of the Bolt11InvoiceFeatures.
*/
hash() {
const ret = bindings.Bolt11InvoiceFeatures_hash(this.ptr);
return ret;
}
/**
* Getting a route for a keysend payment to a private node requires providing the payee's
* features (since they were not announced in a node announcement). However, keysend payments
* don't have an invoice to pull the payee's features from, so this method is provided for use
* when a [`Bolt11InvoiceFeatures`] is required in a route.
*
* MPP keysend is not widely supported yet, so we parameterize support to allow the user to
* choose whether their router should find multi-part routes.
*/
static constructor_for_keysend(allow_mpp) {
const ret = bindings.Bolt11InvoiceFeatures_for_keysend(allow_mpp);
const ret_hu_conv = new Bolt11InvoiceFeatures(null, ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Create a blank Features with no features set
*/
static constructor_empty() {
const ret = bindings.Bolt11InvoiceFeatures_empty();
const ret_hu_conv = new Bolt11InvoiceFeatures(null, ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Returns the feature set as a list of bytes, in little-endian. This is in reverse byte order
* from most on-the-wire encodings.
*/
le_flags() {
const ret = bindings.Bolt11InvoiceFeatures_le_flags(this.ptr);
const ret_conv = bindings.decodeUint8Array(ret);
return ret_conv;
}
/**
* Returns true if this `Features` has any optional flags set
*/
supports_any_optional_bits() {
const ret = bindings.Bolt11InvoiceFeatures_supports_any_optional_bits(this.ptr);
return ret;
}
/**
* Returns true if this `Features` object contains required features unknown by `other`.
*/
requires_unknown_bits_from(other) {
const ret = bindings.Bolt11InvoiceFeatures_requires_unknown_bits_from(this.ptr, CommonBase.get_ptr_of(other));
CommonBase.add_ref_from(this, other);
return ret;
}
/**
* Returns the set of required features unknown by `other`, as their bit position.
*/
required_unknown_bits_from(other) {
const ret = bindings.Bolt11InvoiceFeatures_required_unknown_bits_from(this.ptr, CommonBase.get_ptr_of(other));
const ret_conv = bindings.decodeUint64Array(ret);
CommonBase.add_ref_from(this, other);
return ret_conv;
}
/**
* Returns true if this `Features` object contains unknown feature flags which are set as
* \"required\".
*/
requires_unknown_bits() {
const ret = bindings.Bolt11InvoiceFeatures_requires_unknown_bits(this.ptr);
return ret;
}
/**
* Returns true if this `Features` supports any bits which we do not know of
*/
supports_unknown_bits() {
const ret = bindings.Bolt11InvoiceFeatures_supports_unknown_bits(this.ptr);
return ret;
}
/**
* Sets a required feature bit. Errors if `bit` is outside the feature range as defined
* by [BOLT 9].
*
* Note: Required bits are even. If an odd bit is given, then the corresponding even bit will
* be set instead (i.e., `bit - 1`).
*
* [BOLT 9]: https://github.com/lightning/bolts/blob/master/09-features.md
*/
set_required_feature_bit(bit) {
const ret = bindings.Bolt11InvoiceFeatures_set_required_feature_bit(this.ptr, bit);
const ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Sets an optional feature bit. Errors if `bit` is outside the feature range as defined
* by [BOLT 9].
*
* Note: Optional bits are odd. If an even bit is given, then the corresponding odd bit will be
* set instead (i.e., `bit + 1`).
*
* [BOLT 9]: https://github.com/lightning/bolts/blob/master/09-features.md
*/
set_optional_feature_bit(bit) {
const ret = bindings.Bolt11InvoiceFeatures_set_optional_feature_bit(this.ptr, bit);
const ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Sets a required custom feature bit. Errors if `bit` is outside the custom range as defined
* by [bLIP 2] or if it is a known `T` feature.
*
* Note: Required bits are even. If an odd bit is given, then the corresponding even bit will
* be set instead (i.e., `bit - 1`).
*
* [bLIP 2]: https://github.com/lightning/blips/blob/master/blip-0002.md#feature-bits
*/
set_required_custom_bit(bit) {
const ret = bindings.Bolt11InvoiceFeatures_set_required_custom_bit(this.ptr, bit);
const ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Sets an optional custom feature bit. Errors if `bit` is outside the custom range as defined
* by [bLIP 2] or if it is a known `T` feature.
*
* Note: Optional bits are odd. If an even bit is given, then the corresponding odd bit will be
* set instead (i.e., `bit + 1`).
*
* [bLIP 2]: https://github.com/lightning/blips/blob/master/blip-0002.md#feature-bits
*/
set_optional_custom_bit(bit) {
const ret = bindings.Bolt11InvoiceFeatures_set_optional_custom_bit(this.ptr, bit);
const ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Set this feature as optional.
*/
set_variable_length_onion_optional() {
bindings.Bolt11InvoiceFeatures_set_variable_length_onion_optional(this.ptr);
}
/**
* Set this feature as required.
*/
set_variable_length_onion_required() {
bindings.Bolt11InvoiceFeatures_set_variable_length_onion_required(this.ptr);
}
/**
* Checks if this feature is supported.
*/
supports_variable_length_onion() {
const ret = bindings.Bolt11InvoiceFeatures_supports_variable_length_onion(this.ptr);
return ret;
}
/**
* Checks if this feature is required.
*/
requires_variable_length_onion() {
const ret = bindings.Bolt11InvoiceFeatures_requires_variable_length_onion(this.ptr);
return ret;
}
/**
* Set this feature as optional.
*/
set_payment_secret_optional() {
bindings.Bolt11InvoiceFeatures_set_payment_secret_optional(this.ptr);
}
/**
* Set this feature as required.
*/
set_payment_secret_required() {
bindings.Bolt11InvoiceFeatures_set_payment_secret_required(this.ptr);
}
/**
* Checks if this feature is supported.
*/
supports_payment_secret() {
const ret = bindings.Bolt11InvoiceFeatures_supports_payment_secret(this.ptr);
return ret;
}
/**
* Checks if this feature is required.
*/
requires_payment_secret() {
const ret = bindings.Bolt11InvoiceFeatures_requires_payment_secret(this.ptr);
return ret;
}
/**
* Set this feature as optional.
*/
set_basic_mpp_optional() {
bindings.Bolt11InvoiceFeatures_set_basic_mpp_optional(this.ptr);
}
/**
* Set this feature as required.
*/
set_basic_mpp_required() {
bindings.Bolt11InvoiceFeatures_set_basic_mpp_required(this.ptr);
}
/**
* Checks if this feature is supported.
*/
supports_basic_mpp() {
const ret = bindings.Bolt11InvoiceFeatures_supports_basic_mpp(this.ptr);
return ret;
}
/**
* Checks if this feature is required.
*/
requires_basic_mpp() {
const ret = bindings.Bolt11InvoiceFeatures_requires_basic_mpp(this.ptr);
return ret;
}
/**
* Set this feature as optional.
*/
set_payment_metadata_optional() {
bindings.Bolt11InvoiceFeatures_set_payment_metadata_optional(this.ptr);
}
/**
* Set this feature as required.
*/
set_payment_metadata_required() {
bindings.Bolt11InvoiceFeatures_set_payment_metadata_required(this.ptr);
}
/**
* Checks if this feature is supported.
*/
supports_payment_metadata() {
const ret = bindings.Bolt11InvoiceFeatures_supports_payment_metadata(this.ptr);
return ret;
}
/**
* Checks if this feature is required.
*/
requires_payment_metadata() {
const ret = bindings.Bolt11InvoiceFeatures_requires_payment_metadata(this.ptr);
return ret;
}
/**
* Set this feature as optional.
*/
set_trampoline_routing_optional() {
bindings.Bolt11InvoiceFeatures_set_trampoline_routing_optional(this.ptr);
}
/**
* Set this feature as required.
*/
set_trampoline_routing_required() {
bindings.Bolt11InvoiceFeatures_set_trampoline_routing_required(this.ptr);
}
/**
* Checks if this feature is supported.
*/
supports_trampoline_routing() {
const ret = bindings.Bolt11InvoiceFeatures_supports_trampoline_routing(this.ptr);
return ret;
}
/**
* Checks if this feature is required.
*/
requires_trampoline_routing() {
const ret = bindings.Bolt11InvoiceFeatures_requires_trampoline_routing(this.ptr);
return ret;
}
}
//# sourceMappingURL=Bolt11InvoiceFeatures.mjs.map