stakwork / sphinx-relay

Node.js wrapper for communication between sphinx client and lightning node.
MIT License
248 stars 71 forks source link

Relay

Relay is a Node.js wrapper around LND, handling connectivity and storage for Sphinx. Communication between Relay nodes takes place entirely on the Lightning Network, so it is decentralized, untraceable, and encrypted. Message content is also end-to-end encrypted using client public keys, on the Sphinx app itself.

Relay

Relay stores:

Run your own Sphinx node

Preparations

$ lncli getinfo
> "version": "0.10.0-beta commit=v0.10.0-beta"

If you are already operating your LND

If you have some open/funded channels of 100 000 sat+ capacity, you don't need to do anything else regarding Sphinx-Relay operation; if you don't have enough capacity in your channel(s) - add funds or rebalance your channel(s).

If you just installed your LND

If you do not have any open/funded channels, you might want to open a channel to the Sphinx.chat LND. With a direct channel set up to sphinx.chat, sending messages to sphinx.chat-hosted recipients is slightly cheaper. Please, make your own judgment regarding your privacy/cost efficiency balance.

$ lncli newaddress p2wkh
{
    "address": "<bech32 bitcoin address>"
}

Send 120000 sats (100000 + some for fees + anchor channel wallet reserve) to the provided bitcoin address.

Check your LND wallet balance with

$ lncli walletbalance
{
    "total_balance": "120000",
    "confirmed_balance": "0",
    "unconfirmed_balance": "120000"
}

until it shows:

{
    "total_balance": "120000",
    "confirmed_balance": "120000",
    "unconfirmed_balance": "0"
}
$ lncli connect 023d70f2f76d283c6c4e58109ee3a2816eb9d8feb40b23d62469060a2b2867b77f@54.159.193.149:9735
{

}
$ lncli openchannel 023d70f2f76d283c6c4e58109ee3a2816eb9d8feb40b23d62469060a2b2867b77f --local_amt=100000 --push_amt=5000 --sat_per_vbyte=35
{
    "funding_txid": "<......>"
}

NB Set the right amount of bitcoin transaction fee in sat_per_vbyte We recommend using mempool.space to determine the necessary fee.

You can monitor the progress of the channel creation operation with lncli pendingchannels/lncli listchannels commands; the former will show your channel while the operation is still in progress, the latter will show your channel once it's successfully completed.

Check the payment delivery by making a small payment to the Sphinx.chat LND:

$ lncli sendpayment --dest=023d70f2f76d283c6c4e58109ee3a2816eb9d8feb40b23d62469060a2b2867b77f --final_cltv_delta=10 --amt=5 --keysend
+------------+--------------+--------------+--------------+-----+----------+--------------------+---------+
| HTLC_STATE | ATTEMPT_TIME | RESOLVE_TIME | RECEIVER_AMT | FEE | TIMELOCK | CHAN_OUT           | ROUTE   |
+------------+--------------+--------------+--------------+-----+----------+--------------------+---------+
| SUCCEEDED  |        1.544 |        5.188 | 5            | 0   |   642053 |      <......>      | gameb_1 |
+------------+--------------+--------------+--------------+-----+----------+--------------------+---------+
Amount + fee:   5 + 0 sat
Payment hash:   <......>
Payment status: SUCCEEDED, preimage: <......>

Network connectivity

If you have a permanent public IP on your internet connection and you want your mobile or desktop Sphinx client to connect to it over internet, open port 3001/TCP on your router and create a port forwarding rule for TCP to port 3001 of your machine running Sphinx-Relay. How to do this is not included in this guide. https://www.yougetsignal.com/tools/open-ports/ is one of the many websites that can be used to check if a port is opened on your network.

If you plan to use your Sphinx clients within the local network, then you do not have to do anything special.

If you are using the Docker file, the port is 3300 (1, 2)

Deployment

Connecting a mobile client

Scan the generated QR code with your iOS or Android Sphinx client.

You should see [socket.io] connected! in your Relay console output.

Add some friends' addresses and start chatting!

Connecting a Desktop client

As of this writing, neither of the Desktop Sphinx clients can scan Relay QR codes, nor directly import the connection string (printed by Relay just above the QR code).

To connect your Desktop Sphinx to your Relay:

You should see [socket.io] connected! in your Relay console output.

Troubleshooting

Mobile Sphinx does not scan the generated QR code

Then try again.

Messages sent with your Relay are delivered empty or not delivered at all

Make small manual lightning payments to the Sphinx.chat LND (or the node you are connected to)

$ lncli sendpayment --dest=023d70f2f76d283c6c4e58109ee3a2816eb9d8feb40b23d62469060a2b2867b77f --final_cltv_delta=10 --amt=5 --keysend

Then make manual payments to your destination address.

Make sure all payments complete successfully.

Try messaging again in both directions. Usually, as the first messages is successfully delivered, there are no futher issues.

Known issues

There are several known issues at the time of the writing of this document. You can check their actual status on GitHub

Roadmap