#bitcoin #noise #bolt8

lnsocket

An async lightning network socket with with core-lightning rpc support

8 releases (4 breaking)

Uses new Rust 2024

0.5.2 Aug 19, 2025
0.5.1 Aug 10, 2025
0.4.0 Aug 8, 2025
0.3.0 Aug 3, 2025
0.1.1 Aug 2, 2025

#40 in #noise

Download history 176/week @ 2025-07-29 459/week @ 2025-08-05 131/week @ 2025-08-12 214/week @ 2025-08-19 85/week @ 2025-08-26 363/week @ 2025-09-02 201/week @ 2025-09-09 14/week @ 2025-09-16 14/week @ 2025-09-23 122/week @ 2025-09-30 9/week @ 2025-10-07 238/week @ 2025-10-14 41/week @ 2025-10-21 68/week @ 2025-10-28 271/week @ 2025-11-04 82/week @ 2025-11-11

531 downloads per month

MIT license

260KB
5K SLoC

lnsocket-rs

A Rust library for establishing connections to Lightning Network nodes. This library provides low-level primitives for establishing encrypted communication channels with Lightning Network nodes using the Noise_XK protocol as specified in BOLT #8.

lnsocket also comes batteries included with Commando support, allowing you to call RPCs on core-lightning nodes remotely!

Features

  • Establish encrypted connections to Lightning Network nodes with Noise_XK handshake protocol
  • Send and receive Lightning Network messages
  • Support for Commando CLN RPC messages

Usage

Add to your Cargo.toml:

[dependencies]
lnsocket = "0.1.0"

Commando over LNSocket

This crate includes a small Commando client that runs over the same encrypted Lightning transport.

use bitcoin::secp256k1::{SecretKey, PublicKey, rand};
use lnsocket::{LNSocket, CommandoClient};
use serde_json::json;
use lnsocket::commando::CallOpts;

async fn commando_rpc_demo(pk: PublicKey, rune: &str) -> Result<(), lnsocket::Error> {
    let key = SecretKey::new(&mut rand::thread_rng());
    let sock = LNSocket::connect_and_init(key, pk, "ln.example.com:9735").await?;
    let client = CommandoClient::spawn(sock, rune);

    // Inherit client defaults (30s timeout, auto-reconnect with backoff,
    // and retry up to 3 times). Override per call if needed:
    let res = client.call("getinfo", json!({})).await?;
    println!("{}", res);

    let opts = CallOpts::new().timeout(std::time::Duration::from_secs(5)).retry(5);
    let channels = client.call_with_opts("listchannels", json!({}), &opts).await?;
    Ok(())
}

Status

This library is experimental and under active development. APIs may change significantly between versions.

License

This library contains code derived from LDK, which is licensed under either of:

at your option.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Dependencies

~11–24MB
~263K SLoC