UNPKG

lightningdevkit

Version:
118 lines 5.39 kB
import { BlindedPaymentPath } from '../structs/BlindedPaymentPath.mjs'; import { RouteHint } from '../structs/RouteHint.mjs'; import { Bolt11InvoiceFeatures } from '../structs/Bolt11InvoiceFeatures.mjs'; import { Bolt12InvoiceFeatures } from '../structs/Bolt12InvoiceFeatures.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * The recipient of a payment, differing based on whether they've hidden their identity with route * blinding. */ export class Payee extends CommonBase { constructor(_dummy, ptr) { super(ptr, bindings.Payee_free); } /* @internal */ static constr_from_ptr(ptr) { const raw_ty = bindings.LDKPayee_ty_from_ptr(ptr); switch (raw_ty) { case 0: return new Payee_Blinded(ptr); case 1: return new Payee_Clear(ptr); default: throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface } } clone_ptr() { const ret = bindings.Payee_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the Payee */ clone() { const ret = bindings.Payee_clone(this.ptr); const ret_hu_conv = Payee.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Utility method to constructs a new Blinded-variant Payee */ static constructor_blinded(route_hints, features) { const ret = bindings.Payee_blinded(bindings.encodeUint64Array(route_hints.map(route_hints_conv_20 => CommonBase.get_ptr_of(route_hints_conv_20))), CommonBase.get_ptr_of(features)); const ret_hu_conv = Payee.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Utility method to constructs a new Clear-variant Payee */ static constructor_clear(node_id, route_hints, features, final_cltv_expiry_delta) { const ret = bindings.Payee_clear(bindings.encodeUint8Array(node_id), bindings.encodeUint64Array(route_hints.map(route_hints_conv_11 => CommonBase.get_ptr_of(route_hints_conv_11))), CommonBase.get_ptr_of(features), final_cltv_expiry_delta); const ret_hu_conv = Payee.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Generates a non-cryptographic 64-bit hash of the Payee. */ hash() { const ret = bindings.Payee_hash(this.ptr); return ret; } /** * Checks if two Payees contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. */ eq(b) { const ret = bindings.Payee_eq(this.ptr, CommonBase.get_ptr_of(b)); return ret; } } /** A Payee of type Blinded */ export class Payee_Blinded extends Payee { /* @internal */ constructor(ptr) { super(null, ptr); const route_hints = bindings.LDKPayee_Blinded_get_route_hints(ptr); const route_hints_conv_20_len = bindings.getArrayLength(route_hints); const route_hints_conv_20_arr = new Array(route_hints_conv_20_len).fill(null); for (var u = 0; u < route_hints_conv_20_len; u++) { const route_hints_conv_20 = bindings.getU64ArrayElem(route_hints, u); const route_hints_conv_20_hu_conv = new BlindedPaymentPath(null, route_hints_conv_20); CommonBase.add_ref_from(route_hints_conv_20_hu_conv, this); route_hints_conv_20_arr[u] = route_hints_conv_20_hu_conv; } bindings.freeWasmMemory(route_hints); this.route_hints = route_hints_conv_20_arr; const features = bindings.LDKPayee_Blinded_get_features(ptr); const features_hu_conv = new Bolt12InvoiceFeatures(null, features); CommonBase.add_ref_from(features_hu_conv, this); this.features = features_hu_conv; } } /** A Payee of type Clear */ export class Payee_Clear extends Payee { /* @internal */ constructor(ptr) { super(null, ptr); const node_id = bindings.LDKPayee_Clear_get_node_id(ptr); const node_id_conv = bindings.decodeUint8Array(node_id); this.node_id = node_id_conv; const route_hints = bindings.LDKPayee_Clear_get_route_hints(ptr); const route_hints_conv_11_len = bindings.getArrayLength(route_hints); const route_hints_conv_11_arr = new Array(route_hints_conv_11_len).fill(null); for (var l = 0; l < route_hints_conv_11_len; l++) { const route_hints_conv_11 = bindings.getU64ArrayElem(route_hints, l); const route_hints_conv_11_hu_conv = new RouteHint(null, route_hints_conv_11); CommonBase.add_ref_from(route_hints_conv_11_hu_conv, this); route_hints_conv_11_arr[l] = route_hints_conv_11_hu_conv; } bindings.freeWasmMemory(route_hints); this.route_hints = route_hints_conv_11_arr; const features = bindings.LDKPayee_Clear_get_features(ptr); const features_hu_conv = new Bolt11InvoiceFeatures(null, features); CommonBase.add_ref_from(features_hu_conv, this); this.features = features_hu_conv; this.final_cltv_expiry_delta = bindings.LDKPayee_Clear_get_final_cltv_expiry_delta(ptr); } } //# sourceMappingURL=Payee.mjs.map