LN Service
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
async-util add graph subscription method Oct 4, 2018
bolt11 abstract out bolt07 support Dec 7, 2018
lightning make min htlc size attribute naming consistent Dec 13, 2018
push add graph subscription method Oct 4, 2018
reporting abstract out bolt07 support Dec 7, 2018
routers refactor unit tests into dirs Nov 3, 2018
routing make min htlc size attribute naming consistent Dec 13, 2018
service add test for getting fee rates Oct 18, 2018
test test for structured payment errors Dec 14, 2018
.gitignore update directory paths for 0.5 path changes Sep 1, 2018
.tm_properties Basic ln service Mar 21, 2017
LICENSE pull in bolt 11 parsing from bitcoinjslib wip Apr 12, 2018
README.md move to socket naming and expose local lnd Oct 15, 2018
addPeer.js fix request description parsing, include final cltv delta Oct 1, 2018
closeChannel.js adjust formatting Oct 15, 2018
createChainAddress.js fix request description parsing, include final cltv delta Oct 1, 2018
createInvoice.js fix request description parsing, include final cltv delta Oct 1, 2018
createSeed.js stub integration tests Sep 24, 2018
createWallet.js stub integration tests Sep 24, 2018
decodePaymentRequest.js add bolt11 hop hint parsing Oct 1, 2018
getChainBalance.js fix request description parsing, include final cltv delta Oct 1, 2018
getChainTransactions.js fix request description parsing, include final cltv delta Oct 1, 2018
getChannel.js make min htlc size attribute naming consistent Dec 13, 2018
getChannelBalance.js stub integration tests Sep 24, 2018
getChannels.js fix request description parsing, include final cltv delta Oct 1, 2018
getClosedChannels.js stub integration tests Sep 24, 2018
getFeeRates.js add test for getting fee rates Oct 18, 2018
getForwards.js add get forwards method Oct 21, 2018
getInvoice.js add received values to invoice lookups Oct 9, 2018
getInvoices.js add received values to invoice lookups Oct 9, 2018
getNetworkGraph.js make min htlc size attribute naming consistent Dec 13, 2018
getNetworkInfo.js make min htlc size attribute naming consistent Dec 13, 2018
getNode.js fix request description parsing, include final cltv delta Oct 1, 2018
getPayments.js stub integration tests Sep 24, 2018
getPeers.js fix request description parsing, include final cltv delta Oct 1, 2018
getPendingChainBalance.js stub integration tests Sep 24, 2018
getPendingChannels.js add test for get channels Oct 4, 2018
getRoutes.js add test, extended routes argument for get routes Nov 3, 2018
getWalletInfo.js add test, extended routes argument for get routes Nov 3, 2018
index.js abstract out bolt07 support Dec 7, 2018
openChannel.js fix policy calculation error in manual routes construction Nov 6, 2018
package-lock.json make min htlc size attribute naming consistent Dec 13, 2018
package.json make min htlc size attribute naming consistent Dec 13, 2018
pay.js Allow paying invoices with no amount Oct 20, 2018
removePeer.js stub integration tests Sep 24, 2018
sendToChainAddress.js adjust formatting Oct 15, 2018
server.js add graph subscription method Oct 4, 2018
signMessage.js stub integration tests Sep 24, 2018
stopDaemon.js change network graph edges to channels, add stop method Nov 6, 2018
unlockWallet.js stub integration tests Sep 24, 2018
updateRoutingFees.js fix request description parsing, include final cltv delta Oct 1, 2018
verifyMessage.js stub integration tests Sep 24, 2018

README.md

Lightning Network Service

npm version

Overview

The core of this project is a gRPC interface for node.js projects, available through npm.

The project can be run alone to create a simplified REST interface on top of LND that exposes functionality to client applications.

It is recommended to not expose the REST interface directly to the dangerous internet as that gives anyone control of your node.

Installation Instructions

The service can run in two modes:

  1. As a library that can be used directly with GRPC against LND
  2. A standalone REST service that uses a simplified authentication for RPC calls.

The direct GRPC mode is recommended.

Install LND and/or your Bitcoin Chain Daemon

https://github.com/lightningnetwork/lnd/blob/master/docs/INSTALL.md

If using Bitcoin Core, the following ~/.bitcoin/bitcoin.conf configuration is recommended:

assumevalid= // plug in the current best block hash
daemon=1
dbcache=3000
disablewallet=1
rpcpassword= // make a strong password
rpcuser=bitcoinrpc
server=1
testnet=1 // Set as applicable
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333

Sample LND configuration options (~/.lnd/lnd.conf)

[Application Options]
externalip=IP
rpclisten=0.0.0.0:10009
tlsextraip=IP

[Bitcoin]
bitcoin.active=1
bitcoin.mainnet=1
bitcoin.node=bitcoind

Using in GRPC mode as an npm package

You can install the service via npm -

$ npm install ln-service

Run base64 on the tls.cert and admin.macaroon files to get the encoded authentication data to create the LND connection. You can find these files in the LND directory. (~/.lnd or ~/Library/Application Support/Lnd)

$ base64 tls.cert
$ base64 data/chain/bitcoin/mainnet/admin.macaroon

Be careful to avoid copying any newline characters.

You can then interact with your LND node directly:

const lnService = require('ln-service');

const lnd = lnService.lightningDaemon({
  cert: 'base64 encoded tls.cert',
  macaroon: 'base64 encoded admin.macaroon',
  socket: 'localhost:10009',
});

lnService.getWalletInfo({lnd}, (error, result) => {
  console.log(result);
});

Promises are also supported to allow async/await syntax

const getWalletInfo = require('ln-service/getWalletInfo');

const walletInfo = await getWalletInfo({lnd});

console.log(walletInfo.public_key);

If you are interacting with your node remotely, make sure to set:

tlsextraip=YOURIP

In the lnd.conf file for your LND, and regenerate TLS certs by deleting them.

If using a domain for your LND, use the domain option:

tlsextradomain=YOURDOMAIN

Using as a stand-alone REST API

git clone https://github.com/alexbosworth/ln-service.git
cd ln-service
npm install

Configuring Environment Variables

In NPM installed direct GRPC mode only GRPC_SSL_CIPHER_SUITES environment variable is needed

export GRPC_SSL_CIPHER_SUITES='HIGH+ECDSA'

In REST mode:

For convenience in REST mode, you can make a .env file with KEY=VALUE pairs instead of setting environment variables.

Environment variables:

export GRPC_SSL_CIPHER_SUITES='HIGH+ECDSA'
export LNSERVICE_CHAIN="bitcoin" // or litecoin
export LNSERVICE_LND_DIR='~/.lnd/'
export LNSERVICE_NETWORK="testnet" // or mainnet
export LNSERVICE_SECRET_KEY=REPLACE!WITH!SECRET!KEY!

Setting environment variables in Linux:

  • Edit .bashrc or ~/.profile
  • $ source ~/.bashrc in the window you are running the service from

Setting environment variables in MacOS:

  • Edit ~/.bash_profile
  • $ . ~/.bash_profile in the window you are running the service from

Running REST API

$ npm start

Making HTTP requests to the REST API

ln-service uses Basic Authentication currently. Make sure that the request has an authorization header that contains Base64 encoded credentials.

Basic example of an authorization header -

Authorization: Basic {{TOKEN_GOES_HERE_WITHOUT_BRACES}}

To generate the Base64 encoded credentials in Chrome for example in the console you can -

> let username = 'test';
// username can be anything.
> let password = '1m5secret4F';
// password must match the LNSERVICE_SECRET_KEY in your environment variables.
> btoa(`${username}:${password}`);
// dGVzdDoxbTVlY3JldDRG

And then set the value of the Authorization header to the returned value dGVzdDoxbTVlY3JldDRG.

And copy the result as the token in the above example

Running the tests

$ npm test

Integration Tests

btcd and lnd are required to execute the integration tests.

$ tap test/integration/*.js