A simple C library for sending messages over the lightning network

Overview
lnsocket
========

A simple C library for sending messages over the lightning network

Work in progress!

Thanks to Rusty and the clightning project for much of this code, I have
adapted it to be more library friendly. I've removed references to tal, Rusty's
hierarchical allocator. The library only allocates once and uses that chunk of
memory for all operations.


Motivation
----------

I wanted a way to send custom messages to my lightning node, such as RPC.
Building this as a simple C library will allow you to speak the lightning
network in native applications, like on mobile. I have not tested this on iOS
yet but that is planned and is the motivating use case.


Dependencies
------------

You'll need libtool/autoconf/automake for the libsodium/secp256k1 submodules,
but otherwise there are no dependencies


Building
--------

make


Examples
--------

* See test.c for a ping/pong example

* See rpc.c for an RPC example

Contributing
------------

Send patches to [email protected]:

$ git config format.subjectPrefix 'PATCH lnsocket'
$ git config sendemail.to 'William Casarin 
  '
$ git send-email --annotate HEAD^

See 
  https://git-send-email.io/ for configuring your mailer

 
Comments
  • Websockets not connecting

    Websockets not connecting

    Hey, I have tried connecting to my node in the browser via WebSocket and it refuses to connect for some reason. It works great via Node JS, but not in the browser.

    I have also tried using lnlink and I get the same error. Is there anything special that needs to be done with port forwarding for the WS connection to work?

    opened by aaronbarnardsound 10
  • Usage with node

    Usage with node

    Hey! Is this the right way to use with node.js? I can't seem to get it to work.

    import LNSocket from 'lnsocket';
    
    async function go() {
      try {
        const ln = await LNSocket();
    
        ln.genkey();
        await ln.connect_and_init('033292f0c69eea1b98243e0d11ea5891b828d6af75e73bc1392829f38116738880', 'localhost:9989');
    
        console.log('here');
        const rune = 'QRYFkn72bekGstvuETooJQvD9ouRfwG6WoW8IU0cV1I9MA==';
        const res = await ln.rpc({ method: 'getinfo', rune });
    
        ln.destroy();
        console.log(res);
        return res;
      } catch (err) {
        console.log(err);
      }
    }
    
    go();
    
    opened by niteshbalusu11 9
  • make js: emcc error

    make js: emcc error

    $ make js
    ...
    emcc --pre-js lnsocket_pre.js -s ENVIRONMENT=web -s MODULARIZE -flto -s 'EXPORTED_FUNCTIONS=["_malloc", "_free"]' -s EXPORTED_RUNTIME_METHODS=ccall,cwrap -Wall -Os -Ideps/secp256k1/include -Ideps/libsodium/src/libsodium/include -Ideps -Wl,-whole-archive target/js/libsecp256k1.a target/js/libsodium.a target/js/lnsocket.a -Wl,-no-whole-archive -o target/tmp/js/lnsocket.js
    emcc: error: setting `EXPORTED_RUNTIME_METHODS` expects `<class 'list'>` but got `<class 'str'>`
    make: *** [Makefile:203: target/tmp/js/lnsocket.js] Error 1
    
    opened by jsarenik 3
  • add tor proxy support to connect on onion endpoint

    add tor proxy support to connect on onion endpoint

    Add tor proxy support to connect on clightning node through onion endpoint.

    For test with tor, pass tor socks5 istance on lnrpc.c:

    	if (!(ok = lnsocket_connect(ln, nodeid, host, "127.0.0.1:9050")))
    		goto done;
    
    opened by lvaccaro 2
  • Add rust bindings

    Add rust bindings

    Use bindgen to add rust bindings at lnsocket C library.

    Generate rust bindings and target library with:

    make rust
    

    In rust/lib.rs, I open a demo socket connection to my experimental local node.

    I am not a rust expert, so I open MR for feedbacks.

    NOTE: on arm64 platform, the code failed to compile: it expects a *mut u8 instead *mut i8 on CStr::from_ptr().

    opened by lvaccaro 2
  • cannot open output file test: Is a directory

    cannot open output file test: Is a directory

    $ make
    ...
    cc test.o
    cc   test.o   -o test
    /usr/bin/ld: cannot open output file test: Is a directory
    collect2: error: ld returned 1 exit status
    make: *** [<builtin>: test] Error 1
    
    opened by jsarenik 2
  • getting a build error running `make`

    getting a build error running `make`

    ld test
    cc -Wall -Os -Ideps/secp256k1/include -Ideps/libsodium/src/libsodium/include -Ideps test.o sha256.o hkdf.o hmac.o sha512.o lnsocket.o error.o handshake.o crypto.o bigsize.o commando.o bech32.o libsecp256k1.a libsodium.a lnsocket.a  -o test
    /usr/bin/ld: handshake.o: in function `lnsocket_act_two':
    handshake.c:(.text+0x3c3): undefined reference to `secp256k1_ecdh'
    /usr/bin/ld: handshake.c:(.text+0x53a): undefined reference to `secp256k1_ecdh'
    /usr/bin/ld: handshake.o: in function `act_one_initiator_prep':
    handshake.c:(.text+0x6dc): undefined reference to `secp256k1_ecdh'
    collect2: error: ld returned 1 exit status
    make: *** [Makefile:170: test] Error 1
    
    opened by niftynei 2
  • rust: fix library build inside cargo command

    rust: fix library build inside cargo command

    Updates to build lnsocket library through cargo and archive it in a rust package.

    Tested on https://github.com/lvaccaro/btctipserver/blob/62aaddac37b0a7ee4a18d6e90e7276e2f6351440/Cargo.toml#L31

    opened by lvaccaro 1
  • Pure JS client

    Pure JS client

    @ShahanaFarooqui wrote a pure-js commando client here: https://github.com/ShahanaFarooqui/CLN-Commando-Client

    I should just switch to that instead of using the C wasm build.

    opened by jb55 7
  • Decrypt Error

    Decrypt Error

    When sending multiple RPC requests at once I get the following errors:

    Screen Shot 2022-07-27 at 8 38 06 pm

    When the requests are made separately waiting for each one to complete they all work perfectly, but when fired off at the same time the above error occurs.

    I could just wait for each request to receive a response before sending the next one except in the case of long running requests such as waitinvoice which would block other requests for long periods, so it would be nice to be able to send requests in parallel if possible.

    opened by aaronbarnardsound 6
  • Static Key

    Static Key

    Is it possible to have a static public key so that the remote node can limit the rune to that key? Or does a new key need to be created every time it is initialised with the gen_key method?

    opened by aaronbarnardsound 11
  • Node Push Data

    Node Push Data

    Is it possible for this library to receive a message from the remote node it is connected to? My use case would be to have a plugin running on the coreln node that listens for events and would then push those events over the lnsocket. Is that possible?

    opened by aaronbarnardsound 5
Releases(v0.3.2)
Owner
William Casarin
William Casarin
Realtime Client/Server app for Linux allowing joystick (and other HID) data to be transferred over a local network

netstick What is it? Netstick enables HID devices to be remotely connected between a "client" and "server" over a network connection. It allows the ke

null 33 Nov 6, 2022
A linux based file-transfer system in terminal. Share Files Over A Network

Introduction A linux based file-transfer system in terminal. Share Files Over A Network Note This Project Is Not Fully Completed Yet But You Are Free

notaweeb 8 Sep 20, 2021
To have platform independent network interfaces over usb which is working with Linux, Windows, Mac OS ect.

To have platform independent network interfaces over usb which is working with Linux, Windows, Mac OS ect. called RNDIS. This project is a RNDIS demo, which addtionally implements a http server. It runs out of the box on a stm32f411 BlackPill board. My RNDIS library with an empty template for the second interface (which can ba UART, CAN, ETH or like in this demo a tcp/ip stack) can be found under following link: https://github.com/RDMsmartnetworks/STM32_HAL_RNDIS

Nico Korn 17 Dec 24, 2022
(Test assignment) Transfer files over the network using a homegrown UDP protocol

Требования Linux x86_64 gcc >= 4.9 (C++11) Сборка $ make Запуск $ make run -j5 -j5 позволяет серверу и четырём клиентам запуститься одновременно. В

Alexander Batischev 2 Dec 18, 2021
A modern C++ network library for developing high performance network services in TCP/UDP/HTTP protocols.

evpp Introduction 中文说明 evpp is a modern C++ network library for developing high performance network services using TCP/UDP/HTTP protocols. evpp provid

Qihoo 360 3.2k Jan 5, 2023
Header-only C++14 library for getting network addresses associated with network interface without name lookups on Windows, macOS, Linux, and FreeBSD

NetIF Get addresses associated with network interfaces on a system without using name lookups. Header-only, requires C++14. Usage Add the header file

GMLC-TDC 9 Oct 17, 2022
Netif - Header-only C++14 library for getting network addresses associated with network interface without name lookups on Windows, macOS, Linux, and FreeBSD

NetIF Get addresses associated with network interfaces on a system without using name lookups. Header-only, requires C++14. Usage Add the header file

GMLC-TDC 9 Oct 17, 2022
XMap is a fast network scanner designed for performing Internet-wide IPv6 & IPv4 network research scanning.

XMap is reimplemented and improved thoroughly from ZMap and is fully compatible with ZMap, armed with the "5 minutes" probing speed and novel scanning techniques. XMap is capable of scanning the 32-bits address space in under 45 minutes.

idealeer 190 Dec 24, 2022
A simple network library powered by epoll and proactor pattern.

spinet A simple network library powered by epoll and proactor pattern. Installation Required cmake version 3.10 or above c++ standard 17 or above git

null 8 Jan 27, 2022
Warp speed Data Transfer (WDT) is an embeddedable library (and command line tool) aiming to transfer data between 2 systems as fast as possible over multiple TCP paths.

WDT Warp speed Data Transfer Design philosophy/Overview Goal: Lowest possible total transfer time - to be only hardware limited (disc or network bandw

Facebook 2.7k Dec 31, 2022
Asynchronous, Header-only C++ HTTP-over-(TCP|UNIX Socket|STDIO) Library

CXXHTTP A C++ library implementing an asynchronous HTTP server and client. To clone this library, make sure you also clone the submodules. The --recur

null 25 Mar 19, 2021
A Simple CLI Network Packet Sniffer

packt packt is a simple CL(command line) network packet sniffer which can run on any unix-like OS including termux (Android). packt works by first ope

null 6 Oct 19, 2022
The C++ Network Library Project -- cross-platform, standards compliant networking library.

C++ Network Library Modern C++ network programming libraries. Join us on Slack: http://slack.cpp-netlib.org/ Subscribe to the mailing list: https://gr

C++ Network Library 1.9k Dec 27, 2022
QUIC, a multiplexed stream transport over UDP

QUIC, a multiplexed stream transport over UDP QUIC is an experimental protocol aimed at reducing web latency over that of TCP. On the surface, QUIC is

Devsisters Corp. 1.7k Dec 31, 2022
Husarnet is a Peer-to-Peer VPN to connect your laptops, servers and microcontrollers over the Internet with zero configuration.

Husarnet Client Husarnet is a Peer-to-Peer VPN to connect your laptops, servers and microcontrollers over the Internet with zero configuration. Key fe

Husarnet 180 Jan 1, 2023
Linux Terminal Service Manager (LTSM) is a set of service programs that allows remote computers to connect to a Linux operating system computer using a remote terminal session (over VNC or RDP)

Linux Terminal Service Manager (LTSM) is a set of service programs that allows remote computers to connect to a Linux operating system computer using a remote terminal session (over VNC)

null 34 Dec 16, 2022
Open hardware to measure EC and pH, drive pumps, and otherwise manage a mid-size hydroponic grow over Wi-Fi.

Hydromisc This is a single PCBA with all the necessary I/O to automate a typical small to mid-size hydroponic grow, controllable over Wi-Fi

null 480 Dec 12, 2022
DS Download Play-compatible (flashme/haxxstation) GBA cart dumper over Wi-Fi

gbaxxdumper DS Download Play-compatible (flashme/haxxstation) GBA cart dumper over Wi-Fi, made by vappster. Uses softmods only, no flashcart/dongle/GC

vappster 25 Dec 18, 2022
A DLL that serves OutputDebugString content over a TCP connection

RemoteDebugView A DLL that serves OutputDebugString content over a TCP connection Usage You will need to compile the DLL and then call the exported fu

hotnops 33 Nov 29, 2022