This commit is contained in:
hatim boufnichel 2024-07-22 16:02:03 +02:00
commit 3a726f583e
16 changed files with 146 additions and 94 deletions

3
.gitignore vendored
View file

@ -15,4 +15,5 @@ data/
.wallet_secret
.wallet_password
.admin_enroll
admin.npub
admin.npub
app.nprofile

View file

@ -8,4 +8,9 @@ RUN npm i
COPY . /app
EXPOSE 1776
EXPOSE 1777
VOLUME ["/app/data"]
CMD [ "npm", "start" ]

168
README.md
View file

@ -1,3 +1,5 @@
# Lightning.Pub
![Lightning.Pub](https://github.com/shocknet/Lightning.Pub/raw/master/pub_logo.png)
![GitHub last commit](https://img.shields.io/github/last-commit/shocknet/Lightning.Pub?style=flat-square)
@ -5,7 +7,6 @@
[![Chat](https://img.shields.io/badge/chat-on%20Telegram-blue?style=flat-square)](https://t.me/ShockBTC)
![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/ShockBTC?style=flat-square&logo=bitcoin)
### Don't just run a Lightning Node, run a Lightning Pub.
"Pub" is a [Nostr](https://nostr.info)-native account system designed to make running Lightning infrastructure for your friends/family/customers easier than previously thought possible.
@ -22,25 +23,36 @@ Additionally, support for optional services are integrated into Pub for operator
By solving the networking and programability hurdles, Pub provides Lightning with a 3rd Layer that enables node-runners, Busineses, and Uncle Jims to more easily bring their personal network into Bitcoin's permissionless economy. In doing so, Pub runners can keep the Lightning Network decentralized, with custodial scaling that is free of fiat rails, large banks, and other forms of high-time-preference shitcoinery.
#### Features:
## Table of Contents
- [Features](#features)
- [Planned Features](#planned-features)
- [Installation](#installation)
- [One-Line Deployment](#one-line-deployment)
- [Docker Installation](#docker-installation)
- [Manual CLI Installation](#manual-cli-installation)
- [Usage Notes](#usage-notes)
- [Misc](#support-development)
## Features
- Wrapper for [`LND`](https://github.com/lightningnetwork/lnd/releases) that can serve accounts over LNURL and NOSTR
- A growing number of [methods](https://github.com/shocknet/Lightning.Pub/blob/master/proto/autogenerated/client.md)
- Automated Channels
- Receives quotes from multiple LSPs including Zeus, Voltage, and Flashsats
- Receives quotes from multiple LSPs including Zeus, Voltage, and Flashsats
- Bootstrap Peering
- A pub node may trust another pub node until it can afford a channel
- A pub node may trust another pub node until it can afford a channel
- Accounting SubLayers for Application Pools and Users
- A fee regime allows applications owners to monetize users, or node operators to host distinctly monetized applications.
- A fee regime allows applications owners to monetize users, or node operators to host distinctly monetized applications.
![Accounts](https://github.com/shocknet/Lightning.Pub/raw/master/accounting_layers.png)
- Connecting via ShockWallet is as easy as pasting an nprofile
- Or use a link to share your nprofile with friends and family
<img src="https://cdn.shockwallet.app/add_src_sm.png" height="20%" alt="Connect Wallet"> <img src="https://cdn.shockwallet.app/src_invite_sm.png" height="20%" alt="Invite Guests">
<img src="https://cdn.shockwallet.app/add_src_sm.png" height="20%" alt="Connect Wallet"> <img src="https://cdn.shockwallet.app/src_invite_sm.png" height="20%" alt="Invite Guests">
## Planned Features
#### Planned
- [ ] A management dashboard is actively being integrated into [ShockWallet](https://github.com/shocknet/wallet2)
- [ ] Nostr native "offers" (successor to LNURL-Pay, Lightning Address, Bxlt12)
- [ ] P2P "LSP" coordination for channel batching over Nostr
@ -50,74 +62,86 @@ By solving the networking and programability hurdles, Pub provides Lightning wit
Dashboard Wireframe:
<img src="https://shockwallet.b-cdn.net/pub_home_ss.png" alt="Pub Dashboard" width="240">
<img src="https://shockwallet.b-cdn.net/pub_home_ss.png" alt="Pub Dashboard" width="240">
## Installation
### One-Line Deployment
Experimental-ish, this installs all dependencies and creates systemd entries. It has been tested in Ubuntu/Debian x64 environments, but is general enough that it should work on most systems. Mac support is there also, but untested. Please report any issues.
Run the following command:
```ssh
sudo wget -qO- https://deploy.lightning.pub | sudo bash
```
> Note: Automatic updates are not implemented, but running the script a second time in the future will gracefully upgrade the existing installation.
### Docker Installation
1. Pull the Docker image:
```ssh
docker pull ghcr.io/shocknet/lightning-pub:latest
```
2. Run the Docker container:
```ssh
docker run -d \
--name lightning-pub \
--network host \
-p 1776:1776 \
-p 1777:1777 \
-v /path/to/local/data:/app/data \
-v $HOME/.lnd:/root/.lnd \
ghcr.io/shocknet/lightning-pub:latest
```
Network host is used so the service can reach a local LND via localhost. LND is assumed to be under the users home folder, update this location as needed.
### Manual CLI Installation
1. Run [LND](https://github.com/lightningnetwork/lnd/releases) if you aren't already:
```ssh
./lnd --bitcoin.active --bitcoin.mainnet --bitcoin.node=neutrino --neutrino.addpeer=neutrino.shock.network --feeurl=https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json
```
2. Download and Install Lightning.Pub:
```ssh
git clone https://github.com/shocknet/Lightning.Pub && cd Lightning.Pub && npm i
```
3. Configure values in the env file:
```ssh
cp env.example .env && nano .env
```
4. Start the service:
```ssh
npm start
```
## Usage Notes
Connect with [wallet2](https://github.com/shocknet/wallet2) using the wallet admin string that gets logged at startup. The nprofile of the node can also be used to send invitation links to guests.
Note that connecting with wallet will create an account on the node, it will not show or have access to the full LND balance.
Additional docs are WIP at [docs.shock.network](https://docs.shock.network)
## Support Development
> [!IMPORTANT]
> ShockWallet and Lightning.Pub are free software. If you would like to see continued development, please show your [**support**](https://github.com/sponsors/shocknet) 😊<br>
> ShockWallet and Lightning.Pub are free software. If you would like to see continued development, please show your [**support**](https://github.com/sponsors/shocknet) 😊
<img src="https://www.gnu.org/graphics/agplv3-with-text-162x68.png" alt="License">
<br>
## Warning
> [!WARNING]
> While this software has been used in a high-profile production environment for over a year, it should still be considered bleeding edge. Special care has been taken to mitigate the risk of drainage attacks, which is a common risk to all Lightning API's. An integrated Watchdog service will terminate spends if it detects a discrepency between LND and the database, for this reason **IT IS NOT RECOMMENDED TO USE PUB ALONGSIDE OTHER ACCOUNT SYSTEMS**. While we give the utmost care and attention to security, **the internet is an adversarial environment and SECURITY/RELIABILITY ARE NOT GUARANTEED- USE AT YOUR OWN RISK**.
## One-Line Deployment
Experimental-ish, it has been tested in Ubuntu/Debian x64 environments but is general enough that it should work on most systems. Mac support is there also, but untested. Please report any issues.
`sudo wget -qO- https://deploy.lightning.pub | sudo bash`
Automatic updates are not implemented, but running the script a second time in the future will gracefully upgrade the existing installation.
## Umbrel Installation
Coming Soon
## Desktop Installation
Coming Soon
## Docker (testing)
`docker pull ghcr.io/shocknet/lightning-pub:latest`
## Manual CLI Installation
#### Notes:
* Use of a reverse proxy is only required if you wish to serve LNURLs
* The service defaults to port `1776`
* Requires [Node.js](https://nodejs.org) >=18.x
* Commands for your specific OS may differ slightly, Ubuntu/Debian used for example
#### Steps:
1) Run [LND](https://github.com/lightningnetwork/lnd/releases) if you aren't already
*Example mainnet startup*:
```
./lnd --bitcoin.active --bitcoin.mainnet --bitcoin.node=neutrino --neutrino.addpeer=neutrino.shock.network --feeurl=https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json
```
2) Download and Install Lightning.Pub
* `git clone https://github.com/shocknet/Lightning.Pub`
* `cd Lightning.Pub && npm i`
3) Configure values to env file as desired
* `cp env.example .env && nano .env`
5) `npm start`
- A default "wallet" application pool will be automatically created, if you wish to create other app pools:
* `curl -XPOST -H 'Authorization: Bearer defined_in_ADMIN_TOKEN_env' -H "Content-type: application/json" -d '{"name":"ExampleApplicationPoolName"}' 'http://localhost:8080/api/admin/app/add'`
5) Connect with [wallet2](https://github.com/shocknet/wallet2) using the wallet nprofile that gets logged at startup.
> [!NOTE]
> Connecting with wallet will create an account on the node, it will not show or have access to the full LND balance
> While this software has been used in a high-profile production environment for over a year, it should still be considered bleeding edge. Special care has been taken to mitigate the risk of drainage attacks, which is a common risk to all Lightning API's. An integrated Watchdog service will terminate spends if it detects a discrepency between LND and the database, for this reason **IT IS NOT RECOMMENDED TO USE PUB ALONGSIDE OTHER ACCOUNT SYSTEMS**. While we give the utmost care and attention to security, **the internet is an adversarial environment and SECURITY/RELIABILITY ARE NOT GUARANTEED- USE AT YOUR OWN RISK**.

View file

@ -9,7 +9,11 @@
#LND_CERT_PATH=~/.lnd/tls.cert
#LND_MACAROON_PATH=~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
LIQUIDITY_PROVIDER_PUB=
#BOOTSTRAP_PEER
# A trusted peer that will hold a node-level account until channel automation becomes affordable
# The developer is used by default or you may specify your own
# To disable this feature entirely overwrite the env with "null"
#LIQUIDITY_PROVIDER_PUB=null
#DB
#DATABASE_FILE=db.sqlite
@ -57,7 +61,7 @@ LSP_MAX_FEE_BPS=100
#NOSTR
# Default relay may become rate-limited without a paid subscription
#NOSTR_RELAYS=wss://strfry.shock.network
#NOSTR_RELAYS=wss://relay.lightning.pub
#LNURL
# Optional

View file

@ -1,7 +1,7 @@
{
"name": "lightning.pub",
"name": "lnpub",
"version": "1.0.0",
"description": "",
"description": "A Nostr based account system and management platform for nodes on Bitcoin's Lightning Network",
"main": "index.js",
"scripts": {
"clean": "rimraf build",
@ -19,7 +19,7 @@
},
"author": "",
"type": "module",
"license": "ISC",
"license": "Affero GPLv3",
"bugs": {
"url": "https://github.com/shocknet/Lightning.Pub/issues"
},

View file

@ -10,7 +10,7 @@ install_lightning_pub() {
fi
log "${PRIMARY_COLOR}Installing${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR}..."
REPO_URL="https://github.com/shocknet/Lightning.Pub/tarball/fix/bootstrap"
REPO_URL="https://github.com/shocknet/Lightning.Pub/tarball/master"
sudo -u $USER_NAME wget $REPO_URL -O $USER_HOME/lightning_pub.tar.gz > /dev/null 2>&1 || {
log "${PRIMARY_COLOR}Failed to download Lightning.Pub.${RESET_COLOR}"
@ -45,7 +45,7 @@ install_lightning_pub() {
fi
# Merge if upgrade
rsync -av --exclude='*.sqlite' --exclude='.env' --exclude='logs' --exclude='node_modules' lightning_pub_temp/ lightning_pub/ > /dev/null 2>&1
rsync -av --exclude='*.sqlite' --exclude='.env' --exclude='logs' --exclude='node_modules' --exclude='.jwt_secret' --exclude='.wallet_secret' --exclude='admin.npub' --exclude='app.nprofile' --exclude='.admin_connect' --exclude='.admin_enroll' lightning_pub_temp/ lightning_pub/ > /dev/null 2>&1
rm -rf lightning_pub_temp
# Load nvm and npm

View file

@ -13,7 +13,7 @@ export type LiquiditySettings = {
}
export const LoadLiquiditySettingsFromEnv = (): LiquiditySettings => {
const lspSettings = LoadLSPSettingsFromEnv()
const liquidityProviderPub = process.env.LIQUIDITY_PROVIDER_PUB || ""
const liquidityProviderPub = process.env.LIQUIDITY_PROVIDER_PUB === "null" ? "" : (process.env.LIQUIDITY_PROVIDER_PUB || "76ed45f00cea7bac59d8d0b7d204848f5319d7b96c140ffb6fcbaaab0a13d44e")
return { lspSettings, liquidityProviderPub, useOnlyLiquidityProvider: false }
}
export class LiquidityManager {

View file

@ -8,7 +8,7 @@ const getEnvOrDefault = (name: string, defaultValue: string): string => {
}
export const LoadNosrtSettingsFromEnv = (test = false) => {
const relaysEnv = getEnvOrDefault("NOSTR_RELAYS", "wss://strfry.shock.network");
const relaysEnv = getEnvOrDefault("NOSTR_RELAYS", "wss://relay.lightning.pub");
return {
relays: relaysEnv.split(' ')
}

View file

@ -14,7 +14,7 @@ INCOMING_INVOICE_FEE_USER_BPS=0 #defined by app this is just default
OUTGOING_INVOICE_FEE_USER_BPS=60 #defined by app this is just default
TX_FEE_INTERNAL_ROOT_BPS=60 #this is applied only to withdrawls from application wallets
TX_FEE_INTERNAL_USER_BPS=60 #defined by app this is just default
NOSTR_RELAYS=wss://strfry.shock.network
NOSTR_RELAYS=wss://relay.lightning.pub
SERVICE_URL=http://localhost:8080
ADMIN_TOKEN=thisisadmin
PORT=8080

View file

@ -12,6 +12,7 @@
<!-- HTML Meta Tags -->
<title>Lightning.Pub</title>
<meta name="description" content="Lightning for Everyone" />
<link rel="icon" type="image/png" href="img/pub_logo.png" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>

View file

@ -12,6 +12,7 @@
<!-- HTML Meta Tags -->
<title>Lightning.Pub</title>
<meta name="description" content="Lightning for Everyone" />
<link rel="icon" type="image/png" href="img/pub_logo.png" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>

View file

@ -138,4 +138,10 @@
var(--gradient) border-box;
border-radius: 2rem;
border: 1px solid transparent;
}
#adminNpub {
font-size: 8px; /* Adjust font size to fit on one line */
text-align: left; /* Left align the text */
line-break: anywhere; /* Ensure long text breaks appropriately */
}

View file

@ -11,6 +11,7 @@
<!-- HTML Meta Tags -->
<title>Lightning.Pub</title>
<meta name="description" content="Lightning for Everyone" />
<link rel="icon" type="image/png" href="img/pub_logo.png" />
</head>
<body>

View file

@ -12,6 +12,7 @@
<!-- HTML Meta Tags -->
<title>Lightning.Pub</title>
<meta name="description" content="Lightning for Everyone" />
<link rel="icon" type="image/png" href="img/pub_logo.png" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>

View file

@ -12,6 +12,7 @@
<!-- HTML Meta Tags -->
<title>Lightning.Pub</title>
<meta name="description" content="Lightning for Everyone" />
<link rel="icon" type="image/png" href="img/pub_logo.png" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>

View file

@ -12,6 +12,7 @@
<!-- HTML Meta Tags -->
<title>Lightning.Pub</title>
<meta name="description" content="Lightning for Everyone" />
<link rel="icon" type="image/png" href="img/pub_logo.png" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
@ -36,7 +37,7 @@
<div style="text-align: left;">Public Node Name:</div>
<div class="fc-grey editable-content">
<div class="show-nodey" style="display: flex; flex-direction: column; display: none;">
<input type="text" value="" name="show-nodey" placeholder="Nodey McNodeFace" />
<input type="text" value="" name="show-nodey" placeholder="" />
<div style="display: flex;justify-content: end;">
<button class="small-btn" id="cancel-show-nodey">Cancel</button>
<button class="small-btn" id="save-show-nodey">Save</button>
@ -76,12 +77,14 @@
</div>
</div>
<div style="display: flex; justify-content: end;padding-right: 12px;">
<div class="marked" id="show-reset" style="text-decoration: underline; margin-top: 5px;position: relative;">
<div class="marked" id="show-reset" style="text-decoration: underline; margin-top: 5px;position: relative; display: none;">
Reset
<div class="watchdog-status">
<button class="icon-button" id="show-question">
<img src="img/question.svg" />
</button>
<a href="https://docs.shock.network/pub/watchdog" target="_blank">
<button class="icon-button" id="show-question">
<img src="img/question.svg" />
</button>
</a>
</div>
</div>
</div>
@ -114,9 +117,11 @@
<div style="position: relative;">
Watchdog Status:
<div class="watchdog-status">
<button class="icon-button" id="show-question">
<img src="img/question.svg" />
</button>
<a href="https://docs.shock.network/pub/watchdog" target="_blank">
<button class="icon-button" id="show-question">
<img src="img/question.svg" />
</button>
</a>
</div>
</div>
<div id="watchdog-status">
@ -143,7 +148,7 @@
<script src="js/status.js"></script>
<script>
const fetchInfo = async () => {
console.log("fewtching...")
console.log("fetching...")
const res = await fetch("/wizard/service_state")
console.log(res)
if (res.status !== 200) {
@ -162,8 +167,10 @@
document.getElementById("relayStatus").innerHTML = `<span class="${j.relay_connected ? 'green-dot' : 'red-dot'}">&#9679;</span> ${j.relay_connected ? 'Connected' : 'Disconnected'}`
document.getElementById("lndStatus").innerHTML = `<span class="${j.lnd_state === 'ONLINE' ? 'green-dot' : 'red-dot'}">&#9679;</span> ${j.lnd_state}`
document.getElementById("watchdog-status").innerHTML = `<span class="${j.watchdog_ok ? 'green-dot' : 'red-dot'}">&#9679;</span> ${j.watchdog_ok ? 'No Alerts' : 'ALERT!!'}`
document.getElementById("inviteLinkHttp").href = `https://my.shockwallet.app/invite/${j.nprofile}`
document.getElementById("inviteLinkHttp").innerHTML = `https://my.shockwallet.app/invite/${j.nprofile}`
document.getElementById("inviteLinkHttp").href = `https://my.shockwallet.app/#/source?addSource=${j.nprofile}`
document.getElementById("inviteLinkHttp").innerHTML = `https://my.shockwallet.app/#/source?addSource=${j.nprofile}`
document.querySelector('input[name="show-nodey"]').placeholder = j.provider_name;
document.title = j.provider_name;
}
try {
fetchInfo()