} as ldk.LoggerInterface);
const logger_b = logger_a;
-const node_a_secret = new Uint8Array(32);
-for (var i = 0; i < 32; i++) node_a_secret[i] = 42;
+const node_a_seed = new Uint8Array(32);
+for (var i = 0; i < 32; i++) node_a_seed[i] = 42;
+const keys_manager_a = ldk.KeysManager.constructor_new(node_a_seed, 0xdeadbeefn, 0xdeadbeef);
// The public key for a secret key of all 42s:
-const node_a_pk = new Uint8Array([3, 91, 229, 233, 71, 130, 9, 103, 74, 150, 230, 15, 31, 3, 127, 97, 118, 84, 15, 208, 1, 250, 29, 100, 105, 71, 112, 197, 106, 119, 9, 196, 44]);
+const node_a_pk = new Uint8Array([2, 199, 152, 57, 62, 230, 84, 174, 99,
+ 219, 13, 9, 134, 214, 253, 64, 62,
+ 214, 150, 255, 176, 173, 44, 221, 102,
+ 195, 152, 169, 215, 195, 79, 251, 240]);
-const node_b_secret = new Uint8Array(32);
-for (var i = 0; i < 32; i++) node_b_secret[i] = 43;
+const node_b_seed = new Uint8Array(32);
+for (var i = 0; i < 32; i++) node_b_seed[i] = 43;
+const keys_manager_b = ldk.KeysManager.constructor_new(node_b_seed, 0xdeadbeefn, 0xdeadbeef);
const rng_seed = new Uint8Array(32);
const routing_handler = ldk.IgnoringMessageHandler.constructor_new().as_RoutingMessageHandler();
const cust_handler = ldk.IgnoringMessageHandler.constructor_new().as_CustomMessageHandler();
const onion_handler = ldk.IgnoringMessageHandler.constructor_new().as_OnionMessageHandler();
-const a_pm = ldk.PeerManager.constructor_new(chan_handler, routing_handler, onion_handler, node_a_secret, 0xdeadbeef, rng_seed, logger_a, cust_handler);
+const a_pm = ldk.PeerManager.constructor_new(chan_handler, routing_handler, onion_handler, 0xdeadbeef, rng_seed, logger_a, cust_handler, keys_manager_a.as_NodeSigner());
const a_net_handler = new node_net.NodeLDKNet(a_pm);
var port = 10000;
for (; port < 11000; port++) {
} catch(_) {}
}
-const b_pm = ldk.PeerManager.constructor_new(chan_handler, routing_handler, onion_handler, node_b_secret, 0xdeadbeef, rng_seed, logger_b, cust_handler);
+const b_pm = ldk.PeerManager.constructor_new(chan_handler, routing_handler, onion_handler, 0xdeadbeef, rng_seed, logger_b, cust_handler, keys_manager_b.as_NodeSigner());
const b_net_handler = new node_net.NodeLDKNet(b_pm);
await b_net_handler.connect_peer("127.0.0.1", port, node_a_pk);
}, 500);
});
-b_pm.disconnect_by_node_id(node_a_pk, false);
+b_pm.disconnect_by_node_id(node_a_pk);
await new Promise<void>(resolve => {
// Wait until A learns the connection is closed from the socket closure
var timer: ReturnType<typeof setInterval>;
var seed_counter = 0;
class Node {
node_id: Uint8Array;
- node_secret: Uint8Array;
constructor(public chan_man: ldk.ChannelManager, public tx_broadcasted: Promise<Uint8Array>,
- public logger: ldk.Logger, public keys_interface: ldk.KeysInterface) {
+ public logger: ldk.Logger, public keys_manager: ldk.KeysManager) {
this.node_id = chan_man.get_our_node_id();
- this.node_secret = (keys_interface.get_node_secret(ldk.Recipient.LDKRecipient_Node) as ldk.Result_SecretKeyNoneZ_OK).res;
}
}
function get_chanman(): Node {
seed.fill(seed_counter);
seed_counter++;
const keys_manager = ldk.KeysManager.constructor_new(seed, BigInt(42), 42);
- const keys_interface = keys_manager.as_KeysInterface();
- const config = ldk.UserConfig.constructor_default();
- const params = ldk.ChainParameters.constructor_new(ldk.Network.LDKNetwork_Testnet, ldk.BestBlock.constructor_from_genesis(ldk.Network.LDKNetwork_Testnet));
- const chan_man = ldk.ChannelManager.constructor_new(fee_est, chain_watch, tx_broadcaster!, logger, keys_interface, config, params);
- return new Node(chan_man, tx_broadcasted, logger, keys_interface);
+ const net_graph = ldk.NetworkGraph.constructor_new(ldk.Network.LDKNetwork_Testnet, logger);
+ const scorer = ldk.ProbabilisticScorer.constructor_new(ldk.ProbabilisticScoringParameters.constructor_default(), net_graph, logger);
+ const lockable_score = ldk.MultiThreadedLockableScore.constructor_new(scorer.as_Score());
+ const router = ldk.DefaultRouter.constructor_new(net_graph, logger, keys_manager.as_EntropySource().get_secure_random_bytes(), lockable_score.as_LockableScore());
+
+ const config = ldk.UserConfig.constructor_default();
+ const params = ldk.ChainParameters.constructor_new(ldk.Network.LDKNetwork_Testnet, ldk.BestBlock.constructor_from_network(ldk.Network.LDKNetwork_Testnet));
+ const chan_man = ldk.ChannelManager.constructor_new(fee_est, chain_watch, tx_broadcaster!, router.as_Router(), logger,
+ keys_manager.as_EntropySource(), keys_manager.as_NodeSigner(), keys_manager.as_SignerProvider(), config, params);
+ return new Node(chan_man, tx_broadcasted, logger, keys_manager);
}
function exchange_messages(a: ldk.ChannelManager, b: ldk.ChannelManager) {
const msg = msgs[j];
if (msg instanceof ldk.MessageSendEvent_SendOpenChannel) {
if (!array_eq(msg.node_id, to.get_our_node_id())) return false;
- const features = from.as_ChannelMessageHandler().provided_init_features(to.get_our_node_id());
- to.as_ChannelMessageHandler().handle_open_channel(from.get_our_node_id(), features, msg.msg);
+ to.as_ChannelMessageHandler().handle_open_channel(from.get_our_node_id(), msg.msg);
} else if (msg instanceof ldk.MessageSendEvent_SendAcceptChannel) {
if (!array_eq(msg.node_id, to.get_our_node_id())) return false;
- const features = from.as_ChannelMessageHandler().provided_init_features(to.get_our_node_id());
- to.as_ChannelMessageHandler().handle_accept_channel(from.get_our_node_id(), features, msg.msg);
+ to.as_ChannelMessageHandler().handle_accept_channel(from.get_our_node_id(), msg.msg);
} else if (msg instanceof ldk.MessageSendEvent_SendFundingCreated) {
if (!array_eq(msg.node_id, to.get_our_node_id())) return false;
to.as_ChannelMessageHandler().handle_funding_created(from.get_our_node_id(), msg.msg);
const features = a.chan_man.as_ChannelMessageHandler().provided_init_features(b.chan_man.get_our_node_id());
- a.chan_man.as_ChannelMessageHandler().peer_connected(b.chan_man.get_our_node_id(), ldk.Init.constructor_new(features, ldk.Option_NetAddressZ.constructor_none()));
- b.chan_man.as_ChannelMessageHandler().peer_connected(a.chan_man.get_our_node_id(), ldk.Init.constructor_new(features, ldk.Option_NetAddressZ.constructor_none()));
+ a.chan_man.as_ChannelMessageHandler().peer_connected(b.chan_man.get_our_node_id(), ldk.Init.constructor_new(features, ldk.Option_NetAddressZ.constructor_none()), false);
+ b.chan_man.as_ChannelMessageHandler().peer_connected(a.chan_man.get_our_node_id(), ldk.Init.constructor_new(features, ldk.Option_NetAddressZ.constructor_none()), true);
const chan_create_err = a.chan_man.create_channel(b.chan_man.get_our_node_id(), BigInt(0), BigInt(400), BigInt(0), ldk.UserConfig.constructor_default());
if (chan_create_err.is_ok()) return false;
const b = get_chanman();
const ignorer = ldk.IgnoringMessageHandler.constructor_new();
- const pm_a = ldk.PeerManager.constructor_new(a.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), ignorer.as_OnionMessageHandler(), a.node_secret, 0xdeadbeef, a.node_secret, a.logger, ignorer.as_CustomMessageHandler());
- const pm_b = ldk.PeerManager.constructor_new(b.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), ignorer.as_OnionMessageHandler(), b.node_secret, 0xdeadbeef, b.node_secret, b.logger, ignorer.as_CustomMessageHandler());
+ const pm_a = ldk.PeerManager.constructor_new(a.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), ignorer.as_OnionMessageHandler(),
+ 0xdeadbeef, a.keys_manager.as_EntropySource().get_secure_random_bytes(), a.logger, ignorer.as_CustomMessageHandler(), a.keys_manager.as_NodeSigner());
+ const pm_b = ldk.PeerManager.constructor_new(b.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), ignorer.as_OnionMessageHandler(),
+ 0xdeadbeef, b.keys_manager.as_EntropySource().get_secure_random_bytes(), b.logger, ignorer.as_CustomMessageHandler(), b.keys_manager.as_NodeSigner());
var sock_b: ldk.SocketDescriptor;
const sock_a = ldk.SocketDescriptor.new_impl({
},
} as ldk.CustomOnionMessageHandlerInterface);
- const underlying_om_a = ldk.OnionMessenger.constructor_new(a.keys_interface, a.logger, om_handler_a);
+ const underlying_om_a = ldk.OnionMessenger.constructor_new(a.keys_manager.as_EntropySource(), a.keys_manager.as_NodeSigner(), a.logger, om_handler_a);
const om_provider_a = {
next_onion_message_for_peer(peer_node_id: Uint8Array): ldk.OnionMessage {
return underlying_om_a.as_OnionMessageProvider().next_onion_message_for_peer(peer_node_id);
handle_onion_message(peer_node_id: Uint8Array, msg: ldk.OnionMessage) {
underlying_om_a.as_OnionMessageHandler().handle_onion_message(peer_node_id, msg);
},
- peer_connected(their_node_id: Uint8Array, init: ldk.Init): ldk.Result_NoneNoneZ {
- return underlying_om_a.as_OnionMessageHandler().peer_connected(their_node_id, init)
+ peer_connected(their_node_id: Uint8Array, init: ldk.Init, inbound: boolean): ldk.Result_NoneNoneZ {
+ return underlying_om_a.as_OnionMessageHandler().peer_connected(their_node_id, init, inbound)
},
- peer_disconnected(their_node_id: Uint8Array, no_connection_possible: boolean) {
- underlying_om_a.as_OnionMessageHandler().peer_disconnected(their_node_id, no_connection_possible);
+ peer_disconnected(their_node_id: Uint8Array) {
+ underlying_om_a.as_OnionMessageHandler().peer_disconnected(their_node_id);
},
provided_node_features(): ldk.NodeFeatures {
return underlying_om_a.as_OnionMessageHandler().provided_node_features();
b_handled_msg = true;
},
} as ldk.CustomOnionMessageHandlerInterface);
- const om_b = ldk.OnionMessenger.constructor_new(b.keys_interface, b.logger, om_handler_b);
+ const om_b = ldk.OnionMessenger.constructor_new(b.keys_manager.as_EntropySource(), b.keys_manager.as_NodeSigner(), b.logger, om_handler_b);
- const pm_a = ldk.PeerManager.constructor_new(a.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), om_a, a.node_secret, 0xdeadbeef, a.node_secret, a.logger, ignorer.as_CustomMessageHandler());
- const pm_b = ldk.PeerManager.constructor_new(b.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), om_b.as_OnionMessageHandler(), b.node_secret, 0xdeadbeef, b.node_secret, b.logger, ignorer.as_CustomMessageHandler());
+ const pm_a = ldk.PeerManager.constructor_new(a.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), om_a,
+ 0xdeadbeef, a.keys_manager.as_EntropySource().get_secure_random_bytes(), a.logger, ignorer.as_CustomMessageHandler(), a.keys_manager.as_NodeSigner());
+ const pm_b = ldk.PeerManager.constructor_new(b.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), om_b.as_OnionMessageHandler(),
+ 0xdeadbeef, b.keys_manager.as_EntropySource().get_secure_random_bytes(), b.logger, ignorer.as_CustomMessageHandler(), b.keys_manager.as_NodeSigner());
var sock_b: ldk.SocketDescriptor;
const sock_a = ldk.SocketDescriptor.new_impl({
tests.push(async () => {
// Test that we can do basic locking of a NetworkGraph
- const genesis_hash = new Uint8Array([0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0xd6, 0x68, 0x9c, 0x08, 0x5a, 0xe1, 0x65, 0x83, 0x1e, 0x93, 0x4f, 0xf7, 0x63, 0xae, 0x46, 0xa2, 0xa6, 0xc1, 0x72, 0xb3, 0xf1, 0xb6, 0x0a, 0x8c, 0xe2, 0x6f]);
const logger = ldk.Logger.new_impl({
log(record: ldk.Record): void {
if (record.get_level() != ldk.Level.LDKLevel_Gossip)
console.log(record.get_module_path() + ": " + record.get_args());
}
} as ldk.LoggerInterface);
- const network_graph = ldk.NetworkGraph.constructor_new(genesis_hash, logger);
+ const network_graph = ldk.NetworkGraph.constructor_new(ldk.Network.LDKNetwork_Testnet, logger);
const graph_lock_1 = network_graph.read_only();
graph_lock_1.free();
const graph_lock_2 = network_graph.read_only();