All Projects → Ride-The-Lightning → C Lightning Rest

Ride-The-Lightning / C Lightning Rest

Licence: mit
REST APIs for c-lightning written in node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to C Lightning Rest

Rtl
Ride The Lightning - A full function web browser app for LND, C-Lightning and Eclair
Stars: ✭ 349 (+843.24%)
Mutual labels:  bitcoin, lightning-network
Lnd
Lightning Network Daemon ⚡️
Stars: ✭ 5,623 (+15097.3%)
Mutual labels:  bitcoin, lightning-network
Mixin
🚀 the Mixin TEE-BFT-DAG network reference implementation
Stars: ✭ 351 (+848.65%)
Mutual labels:  bitcoin, lightning-network
Lightning Onion
Onion Routed Micropayments for the Lightning Network
Stars: ✭ 297 (+702.7%)
Mutual labels:  bitcoin, lightning-network
Lnbook
Mastering the Lightning Network (LN)
Stars: ✭ 931 (+2416.22%)
Mutual labels:  bitcoin, lightning-network
Joule Extension
Lightning payments extension for Chrome
Stars: ✭ 303 (+718.92%)
Mutual labels:  bitcoin, lightning-network
Umbrel
A personal Bitcoin and Lightning node designed for everyone
Stars: ✭ 508 (+1272.97%)
Mutual labels:  bitcoin, lightning-network
Breezmobile
Lightning Network mobile client
Stars: ✭ 225 (+508.11%)
Mutual labels:  bitcoin, lightning-network
Voltage
Voltage is a macOS GUI for c-lightning
Stars: ✭ 24 (-35.14%)
Mutual labels:  bitcoin, lightning-network
Eclair
A scala implementation of the Lightning Network.
Stars: ✭ 892 (+2310.81%)
Mutual labels:  bitcoin, lightning-network
Cyphernode
Modular Bitcoin full-node microservices API server architecture and utilities toolkit to build scalable, secure and featureful apps and services without trusted third parties
Stars: ✭ 273 (+637.84%)
Mutual labels:  bitcoin, lightning-network
Lightninglib
lightninglib is a fork of lnd which aims to be usable as a go library inside any application, including mobile apps.
Stars: ✭ 11 (-70.27%)
Mutual labels:  bitcoin, lightning-network
Polar
One-click Bitcoin Lightning networks for local app development & testing
Stars: ✭ 265 (+616.22%)
Mutual labels:  bitcoin, lightning-network
Node Launcher
Easiest Bitcoin Lightning desktop app, for Windows, macOS, and Linux
Stars: ✭ 319 (+762.16%)
Mutual labels:  bitcoin, lightning-network
Eclair Mobile
An Android wallet for the Lightning Network
Stars: ✭ 231 (+524.32%)
Mutual labels:  bitcoin, lightning-network
Electrum
Electrum Bitcoin Wallet
Stars: ✭ 5,353 (+14367.57%)
Mutual labels:  bitcoin, lightning-network
Bitcoin S
Bitcoin Implementation in Scala
Stars: ✭ 206 (+456.76%)
Mutual labels:  bitcoin, lightning-network
Spark Wallet
⚡️ A minimalistic wallet GUI for c-lightning, accessible over the web or through mobile and desktop apps.
Stars: ✭ 215 (+481.08%)
Mutual labels:  bitcoin, lightning-network
Neutrino
Privacy-Preserving Bitcoin Light Client
Stars: ✭ 564 (+1424.32%)
Mutual labels:  bitcoin, lightning-network
Lnd Grpc Client
A python grpc client/async client for LND ⚡⚡⚡
Stars: ✭ 26 (-29.73%)
Mutual labels:  bitcoin, lightning-network

C-Lightning-REST

REST APIs for c-lightning written in Node.js

Docker image: https://hub.docker.com/repository/docker/saubyk/c-lightning-rest

Setup

Pre-requisite

Installation

Download a specific version by following the instructions on the release page

Download from master (not recommended), by following the below steps:

$ git clone https://github.com/saubyk/c-lightning-REST
$ cd c-lightning-REST
$ npm install

Configuration parameters

The below run time configuration are available, which can be configured either via library specific config file or C-Lightning config file:

  • Port - Port for serving the APIs
  • Documentation port - Port for serving the swagger documentation
  • Protocol - Http protocol for communication with the REST server. Two options are supported https and http(unencrypted and insecure communication between API server and the app)
  • Execution mode - Control for more detailed log info
  • RPC Command - - Enable additional RPC commands for /rpc endpoint

Option 1: Via Config file cl-rest-config.json

For running the server, rename the file sample-cl-rest-config.json to cl-rest-config.json. Following parameters can be configured in the config file:

  • PORT (Default: 3001)
  • DOCPORT (Default: 4001)
  • PROTOCOL (Default: https)
  • EXECMODE (Default: production)
  • RPCCOMMANDS (Default: ["*"])

Option 2: With the plugin configuration, if used as a plugin

If running as a plugin, configure the below options in your c-lightning config file:

  • rest-port
  • rest-docport
  • rest-protocol
  • rest-execmode
  • rest-rpc

Defaults are the same as in option # 1 with the exception that rest-rpc is a comma separated string.

Execute Server

You can choose from the below options to run the API server

Option 1: Run as an API server

$ node cl-rest.js

Access the APIs on the default port 3001 or the port configured in the config file.

Option 2: Run as c-lightning plugin

Pass arguments when launching lightningd:

$ lightningd --plugin=PATH_TO_PLUGIN [--rest-port=N] [--rest-protocol=http|https] [--rest-execmode=MODE]

E.g. $ lightningd --plugin=/Users/<user>/c-lightning-REST/plugin.js --rest-port=3003

OR

Set plugin, [rest-port], [rest-docport], [rest-protocol], and [rest-execmode] in lightningd config

E.g. add below to the config file in .lightning folder

plugin=/Users/<user>/c-lightning-REST/plugin.js
rest-port=3002
rest-docport=4001
rest-protocol=https

Option 3: Running c-lightning-REST as a service (Rpi or Linux platform users)

In case you are running a headless Rpi or a Linux node, you can configure c-lightning-REST as a service.

  • Create c-lightning-REST systemd unit and with the following content. Save and exit.
# Raspibolt c-lightning-REST: systemd unit for c-lightning-REST
# /etc/systemd/system/c-lightning-REST.service

[Unit]
Description=c-lightning-REST daemon
Wants=lightningd.service
After=lightningd.service

[Service]
ExecStart=/usr/bin/node <Full path of the c-lightning-REST folder>/cl-rest.js
User=<user>
Restart=always
TimeoutSec=120
RestartSec=30

[Install]
WantedBy=multi-user.target
  • enable and start c-lightning-REST
$ sudo systemctl enable c-lightning-REST
$ sudo systemctl start c-lightning-REST
  • montior the c-lightning-REST log file in realtime(exit with Ctrl-C)

$ sudo journalctl -f -u c-lightning-REST

Security

With the default config, APIs will be served over https (a self signed certificate and key will be generated in the certs folder with openssl).

Sample url: https://localhost:3001/v1/getinfo/

Authentication

Authentication has been implemented with macaroons. Macaroons are bearer tokens, which will be verified by the server. A file access.macaroon will be generated in the certs folder in the application root. The access.macaroon has to be read by the requesting application, converted to base64 or hex, and passed in the header with key value macaroon.

Encoding Options for passing macaroon in the header:

Option 1 - base64

  • Request header: macaroon set as the macaroon coverted to base64 string.
  • Sample code to convert macaroon to base64 string:
var abc = fs.readFileSync (macaroonFile);
var macaroon = Buffer.from(abc).toString("base64");

Option 2 - hex

  • Request header: macaroon set as the macaroon coverted to hex string and encodingtype with value set as hex
  • Sample code to convert macaroon to hex string:
var abc = fs.readFileSync (macaroonFile);
var macaroon = Buffer.from(abc).toString("hex");

If you need help converting your macaroon to hex format you can use the Node.js script from the Zeus project, found here. Alternatively, if you're running a Unix-based operating system (eg. macOS, Linux) you can run xxd -ps -u -c 1000 /path/to/access.macaroon to generate your macaroon in hex format.

API Documentation

Sample url for Swagger documentation of APIs: http://localhost:4001/api-docs/

C-Lightning commands covered by this API suite is here

General Node info

  • getinfo (/v1/getinfo) - GET: Get node information
  • listfunds (/v1/listFunds) - GET: Returns on-chain funds and channel funds information
  • getbalance (/v1/getBalance) - GET: Returns total, confirmed and unconfirmed on-chain balances
  • getfees (/v1/getFees) - GET: Returns the routing fee collected by the node
  • signmessage (/v1/utility/signMessage) - POST: Creates a digital signature of the message using node's secret key
  • verifymessage(/v1/utility/verifyMessage) - GET: Verifies a signature and the pubkey of the node which signed the message

On-Chain fund management

  • newaddr (/v1/newaddr) - GET: Generate address for recieving on-chain funds
  • withdraw (/v1/withdraw) - POST: Withdraw on-chain funds to an address

Peer management

  • connect (/v1/peer/connect) - POST: Connect with a network peer
  • listpeers (/v1/peer/listPeers) - GET: Returns the list of peers connected with the node
  • disconnect (/v1/peer/disconnect) - DEL: Disconnect from a connected network peer

Channel management

  • fundchannel (/v1/channel/openChannel) - POST: Open channel with a connected peer node
  • listchannels (/v1/channel/listChannels) - GET: Get the list of channels open on the node
  • setchannelfee (/v1/channel/setChannelFee) - POST: Update the fee policy for a channel
  • close (/v1/channel/closeChannel) - DEL: Close channel
  • listforwards (/v1/channel/listForwards) - GET: Get the list of forwarded htlcs by the node
  • localremotebal (/v1/channel/localremotebal) - GET: Summarizes local and remote channel balances on the node

Payments

  • pay (/v1/pay) - POST: Pay a bolt11 invoice
  • listpays (/v1/pay/listPays) - GET: List result of payment {bolt11}, or all
  • listsendpays (/v1/pay/listPayments) - GET: List outgoing payments {bolt11}, or all. This api has more detailed output than listpays
  • decodepay (/v1/pay/decodePay) - GET: Decode the bolt11 invoice
  • keysend (/v1/pay/keysend) - POST: Send funds to a node without an invoice

Invoice

  • invoice (/v1/invoice/genInvoice) - POST: Generates a bolt11 invoice provided amount in msat, label, description, expiry in seconds (optional)
  • listinvoices (/v1/invoice/listInvoices) - GET: Lists the invoice on the node, for a {label} or all.
  • delexpiredinvoice (v1/invoice/delExpiredInvoice) - DEL: Delete expired invoices.
  • delinvoice (v1/invoice/delInvoice) - DEL: Delete a particular invoice with a label and status.

Network

  • getroute (/v1/network/getRoute) - GET: List the best route for the payment of [msatoshi] to a lightning node [id]
  • listnodes (/v1/network/listNode) - GET: Lookup node info from the network graph, for a given [pubkey]
  • listchannels (/v1/network/listChannel) - GET: Lookup channel info from the network graph, for a given [short_channel_id]
  • feerates (/v1/network/feeRates) - GET: Lookup fee rates on the network, for a given rate style (perkb or perkw)
  • estimatefees (/v1/network/estimateFees) - GET: Get the urgent, normal and slow Bitcoin feerates as sat/kVB.

RPC

  • rpc (/v1/rpc) - POST: additional access to RPC comands. Examples of body param for rpc:

No param

{"method": "getinfo}

One param

{"method":"signmessage", "params": ["message"]}

Multiple params

{"method":"mymethod", "params: {"key1": "value1"...}}

PRs are welcome! :-)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].