lightningdevkit
Version:
Lightning Development Kit
116 lines • 5.52 kB
JavaScript
import { InMemorySigner } from '../structs/InMemorySigner.mjs';
import { EntropySource } from '../structs/EntropySource.mjs';
import { NodeSigner } from '../structs/NodeSigner.mjs';
import { SignerProvider } from '../structs/SignerProvider.mjs';
import { OutputSpender } from '../structs/OutputSpender.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
* payments.
*
* A phantom node payment is a payment made to a phantom invoice, which is an invoice that can be
* paid to one of multiple nodes. This works because we encode the invoice route hints such that
* LDK will recognize an incoming payment as destined for a phantom node, and collect the payment
* itself without ever needing to forward to this fake node.
*
* Phantom node payments are useful for load balancing between multiple LDK nodes. They also
* provide some fault tolerance, because payers will automatically retry paying other provided
* nodes in the case that one node goes down.
*
* Note that multi-path payments are not supported in phantom invoices for security reasons.
* Switching between this struct and [`KeysManager`] will invalidate any previously issued
* invoices and attempts to pay previous invoices will fail.
*/
export class PhantomKeysManager extends CommonBase {
/* @internal */
constructor(_dummy, ptr) {
super(ptr, bindings.PhantomKeysManager_free);
}
/**
* Constructs a new EntropySource which calls the relevant methods on this_arg.
* This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
*/
as_EntropySource() {
const ret = bindings.PhantomKeysManager_as_EntropySource(this.ptr);
const ret_hu_conv = new EntropySource(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Constructs a new NodeSigner which calls the relevant methods on this_arg.
* This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
*/
as_NodeSigner() {
const ret = bindings.PhantomKeysManager_as_NodeSigner(this.ptr);
const ret_hu_conv = new NodeSigner(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Constructs a new OutputSpender which calls the relevant methods on this_arg.
* This copies the `inner` pointer in this_arg and thus the returned OutputSpender must be freed before this_arg is
*/
as_OutputSpender() {
const ret = bindings.PhantomKeysManager_as_OutputSpender(this.ptr);
const ret_hu_conv = new OutputSpender(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Constructs a new SignerProvider which calls the relevant methods on this_arg.
* This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
*/
as_SignerProvider() {
const ret = bindings.PhantomKeysManager_as_SignerProvider(this.ptr);
const ret_hu_conv = new SignerProvider(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Constructs a [`PhantomKeysManager`] given a 32-byte seed and an additional `cross_node_seed`
* that is shared across all nodes that intend to participate in [phantom node payments]
* together.
*
* See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and
* `starting_time_nanos`.
*
* `cross_node_seed` must be the same across all phantom payment-receiving nodes and also the
* same across restarts, or else inbound payments may fail.
*
* [phantom node payments]: PhantomKeysManager
*/
static constructor_new(seed, starting_time_secs, starting_time_nanos, cross_node_seed) {
const ret = bindings.PhantomKeysManager_new(bindings.encodeUint8Array(seed), starting_time_secs, starting_time_nanos, bindings.encodeUint8Array(cross_node_seed));
const ret_hu_conv = new PhantomKeysManager(null, ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* See [`KeysManager::derive_channel_keys`] for documentation on this method.
*/
derive_channel_keys(channel_value_satoshis, params) {
const ret = bindings.PhantomKeysManager_derive_channel_keys(this.ptr, channel_value_satoshis, bindings.encodeUint8Array(params));
const ret_hu_conv = new InMemorySigner(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
*/
get_node_secret_key() {
const ret = bindings.PhantomKeysManager_get_node_secret_key(this.ptr);
const ret_conv = bindings.decodeUint8Array(ret);
return ret_conv;
}
/**
* Gets the \"node_id\" secret key of the phantom node used to sign invoices, decode the
* last-hop onion data, etc.
*/
get_phantom_node_secret_key() {
const ret = bindings.PhantomKeysManager_get_phantom_node_secret_key(this.ptr);
const ret_conv = bindings.decodeUint8Array(ret);
return ret_conv;
}
}
//# sourceMappingURL=PhantomKeysManager.mjs.map