Settle interledger payments using Lightning Network
Last updated 2 years ago by kjydavis3 .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @karzak/ilp-plugin-lightning 
SYNC missed versions from official npm registry.



** Still under development, use small amounts of money **

This is a plugin that integrates Lightning to the Interledger network. Using this plugin, one will be able to communicate value from the Bitcoin or Litecoin blockchain to any other currency on the Interledger network.

This plugin assumes that a client already has some payment channel open, connected to the greater lightning network. The following versions will implement the opening and closing of payment channels so that users will not need a pre-existing connection to the lightning network.

If you're unfamiliar with lightning, you can learn more about how it works here.


If you want to run this plugin, you'll need both a lightning and bitcoin node running. The easiest way to do this is likely through setting up a local simnet. Once you have two entities configured, you can enter their credentials in test/test.ts and run node ./build/test/test.js to see a client request an invoice from a server.

Lightning Specific Protocols

The main difference between lightning and the previously integrated currencies (XRP, ETH) are that lightning uses identity public keys (different from public keys used for the blockchain) and all payments must be sent in response to invoices.

Peering Protocol

Once a client establishes a websocket connection to a server, they automatically attempt to peer over lightning.


  • Data:
    • lndIdentitypubkey: lightning identity pubkey
    • lndPeeringHost: lightning peering host:port

Once the server receives the BTP.MESSAGE with sub-protocol peeringRequest, they call connectPeer on their lightning daemon using the data in the packet to identify the client on the lightning network. The server sends a lightning peering request that is automatically accepted, and sends back a BTP.MESSAGE packet with sub-protocol peeringResponse.


  • Data:
    • lndIdentityPubkey: lightning identity pubkey

The client then parses the data from this packet and store the server's identity public key for reference in the future. Peering requests are automatically accepted over lightning. The client does NOT need to perform any lightning level functionality upon receipt of this packet.

Invoice Protocol

When a plugin instance wishes to settle with a counterparty, they must request an invoice before they can make a payment.


  • Data:
    • amount: amount plugin wishes to pay counterparty

Upon receipt of a BTP.MESSAGE packet containing the sub-protocol invoiceRequest a plugin will create an invoice for the requested amount, and send back a BTP.MESSAGE containing the sub-protocol invoiceResponse.


  • Data:
    • paymentRequest: a payment request which can be decoded into an invoice

Upon receipt of a BTP.MESSAGE packet containing the sub-protocol invoiceResponse the plugin will perform the following steps:

  1. Decode the payment request to an invoice
  2. Validate the invoice amount and destination are as expected
  3. Fulfill the invoice
  4. Update their balance
  5. Respond with BTP.MESSAGE containing the sub-protocol invoiceFulfill


  • Data:
    • paymentRequest: a payment request to identify the sent invoice

Upon receipt of a BTP.TRANSFER packet containing the sub-protocol invoiceFulfill the plugin will:

  1. Check their lightning daemon to ensure the specified invoice was actually fulfilled
  2. Update their balance with the counterparty



  • Required
  • Type: string
  • Identity public key used to identify a user on the lightning network.


  • Required
  • Type: string
  • Format: host:port
  • Communication host used to communicate with local lightning daemon


  • Required
  • Type: string
  • Format: host:port
  • Peering host used to listen for p2p communication


  • Type: string
  • Path to the admin.macaroon used to authenticate lightning daemon requests


  • Type: string
  • Path totls.cert


  • Type:
    • "client" to connect to a single counterparty
    • "server" enables multiple counterparties to connect
  • Default: "client"


  • Type: number
  • Only used for server, so that client can connect to through this port


  • Type: string
  • Format: btp+wss://:secret@host:port
  • Only used for client, URI to connect to server


  • Type: BigNumber, number, or string
  • Default: Infinity
  • Maximum number of satoshis in single packet that will be accepted


  • Positive balance: counterparty owes plugin money
  • Negative balance: plugin owes counterparty money


  • Type: BigNumber, number, or string
  • Default: Infinity
  • Maximum balance the counterparty can owe this instance before further packets are rejected


  • Type: BigNumber, number, or string
  • Default: 0
  • Plugin will attempt to settle to this amount after the balance falls below the settleThreshold


  • Type: BigNumber, number, or string
  • Default: -10000
  • Automatically attempts to settle when the balance drops below this number


  • Type: BigNumber, number, or string
  • Default: -Infinity
  • Maximum this instance owes the counterparty before further packets are rejected

Current Tags

  • 1.0.0-beta.2                                ...           latest (2 years ago)

1 Versions

  • 1.0.0-beta.2                                ...           2 years ago
Maintainers (1)
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 1
Last Month 0
Dependencies (10)
Dev Dependencies (12)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |