lnsocket 0.1.1

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

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"

Example

use lnsocket::{LNSocket, CommandoClient};
use bitcoin::secp256k1::{PublicKey, SecretKey};

async fn test_commando() -> Result<(), Error> {
    use crate::commando::CommandoClient;

    let key = SecretKey::new(&mut rand::thread_rng());
    let their_key = PublicKey::from_str(
        "03f3c108ccd536b8526841f0a5c58212bb9e6584a1eb493080e7c1cc34f82dad71",
    )
    .unwrap();

    let mut lnsocket = LNSocket::connect_and_init(key, their_key, "ln.damus.io:9735").await?;
    let mut commando = CommandoClient::new(
        "hfYByx-RDwdBfAK-vOWeOCDJVYlvKSioVKU_y7jccZU9MjkmbWV0aG9kPWdldGluZm8=",
    );
    let resp = commando.call(&mut lnsocket, "getinfo", vec![]).await?;

    println!("{}", serde_json::to_string(&resp).unwrap());

    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.