Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/dynamic-budgets
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Jul 8, 2024
2 parents 02d2027 + e401a1e commit d7b163d
Show file tree
Hide file tree
Showing 121 changed files with 1,047 additions and 635 deletions.
10 changes: 5 additions & 5 deletions .do/deploy.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ spec:
image:
registry_type: GHCR
registry: getalby
repository: nostr-wallet-connect-next
repository: hub
instance_size_slug: basic-xxs
envs:
- key: LDK_ESPLORA_SERVER
value: "https://electrs.albylabs.com"
- key: LOG_EVENTS
value: "true"
- key: LDK_ESPLORA_SERVER
value: "https://electrs.getalby.com"
- key: LOG_EVENTS
value: "true"
2 changes: 1 addition & 1 deletion .github/workflows/http.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
env:
CGO_ENABLED: 1
TAG: ${{ github.ref_name }}
run: go build ${{ env.GOTAGS }} -o build/bin/${{ env.PACKAGE_NAME }}/bin/${{ env.EXEC_NAME }} -ldflags "-X 'github.com/getAlby/nostr-wallet-connect/version.Tag=${{ env.TAG }}'" cmd/http/main.go
run: go build ${{ env.GOTAGS }} -o build/bin/${{ env.PACKAGE_NAME }}/bin/${{ env.EXEC_NAME }} -ldflags "-X 'github.com/getAlby/hub/version.Tag=${{ env.TAG }}'" cmd/http/main.go

- name: Copy shared libraries to the output directory
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/wails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Setup GoLang
uses: actions/setup-go@v5
with:
go-version-file: './go.mod'
go-version-file: "./go.mod"

- name: Get dependencies
run: go get -v -t -d ./...
Expand Down Expand Up @@ -101,17 +101,17 @@ jobs:

- name: Build App
if: runner.os == 'macOS'
run: wails build --platform darwin/universal -webview2 embed -o ${{ env.EXEC_NAME }} -tags "wails" -ldflags "-X 'github.com/getAlby/nostr-wallet-connect/version.Tag=${{ env.TAG }}'"
run: wails build --platform darwin/universal -webview2 embed -o ${{ env.EXEC_NAME }} -tags "wails" -ldflags "-X 'github.com/getAlby/hub/version.Tag=${{ env.TAG }}'"
shell: bash

- name: Build App
if: runner.os == 'Linux'
run: wails build --platform linux/amd64 -webview2 embed -o ${{ env.EXEC_NAME }} -tags "wails" -ldflags "-X 'github.com/getAlby/nostr-wallet-connect/version.Tag=${{ env.TAG }}'"
run: wails build --platform linux/amd64 -webview2 embed -o ${{ env.EXEC_NAME }} -tags "wails" -ldflags "-X 'github.com/getAlby/hub/version.Tag=${{ env.TAG }}'"
shell: bash

- name: Build Windows App
if: runner.os == 'Windows'
run: wails build --platform windows/amd64 -webview2 embed -o ${{ env.EXEC_NAME }}.exe -tags "wails" -ldflags "-X 'github.com/getAlby/nostr-wallet-connect/version.Tag=${{ env.TAG }}'"
run: wails build --platform windows/amd64 -webview2 embed -o ${{ env.EXEC_NAME }}.exe -tags "wails" -ldflags "-X 'github.com/getAlby/hub/version.Tag=${{ env.TAG }}'"
shell: bash

- name: Import Code-Signing Certificates for macOS
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ COPY . .
COPY --from=frontend /build/frontend/dist ./frontend/dist

RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go build \
-ldflags="-X 'github.com/getAlby/nostr-wallet-connect/version.Tag=$TAG'" \
-ldflags="-X 'github.com/getAlby/hub/version.Tag=$TAG'" \
-o main cmd/http/main.go

COPY ./build/docker/copy_dylibs.sh .
Expand Down
38 changes: 23 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nostr Wallet Connect (Next)
# Alby Hub

This is a self-sovereign, self-custodial, single-user rewrite of NWC currently in an experimental phase development. **❗This version is not backwards compatible with NWC - it requires a fresh database and connections to be re-added**
This is a self-sovereign, self-custodial, single-user rewrite of the original [Nostr Wallet Connect](https://github.com/getAlby/nostr-wallet-connect) app. **❗This version is not backwards compatible with the original app - it requires a fresh database and connections to be re-added**

This application allows you to control your Lightning node or wallet from any other application that supports [NWC](https://nwc.dev/).
Connect apps like [Damus](https://damus.io/) or [Amethyst](https://linktr.ee/amethyst.social) to your node. There are many more available on https://nwc.dev/.
Expand All @@ -16,10 +16,12 @@ Ideally the app runs 24/7 (on a node, VPS or always-online desktop/laptop machin

## Supported Backends

- LND (see: lnd.go)
- Breez (see: breez.go)
- Greenlight (see: greenlight.go)
- LDK (see: ldk.go)
- LND
- Breez
- Greenlight
- LDK
- Pheonixd
- Cashu
- want more? please open an issue.

## Installation
Expand Down Expand Up @@ -123,7 +125,7 @@ For more information refer to:

### Versioning

$ go run -ldflags="-X 'github.com/getAlby/nostr-wallet-connect/version.Tag=v0.6.0'" cmd/http/main.go
$ go run -ldflags="-X 'github.com/getAlby/hub/version.Tag=v0.6.0'" cmd/http/main.go

### Windows

Expand All @@ -135,9 +137,9 @@ Breez SDK requires gcc to build the Breez bindings. Run `choco install mingw` an
- `CLIENT_NOSTR_PUBKEY`: if set, this service will only listen to events authored by this public key. You can set this to your own nostr public key.
- `RELAY`: default: "wss://relay.getalby.com/v1"
- `COOKIE_SECRET`: a randomly generated secret string. (only needed in http mode)
- `DATABASE_URI`: a sqlite filename. Default: $XDG_DATA_HOME/nostr-wallet-connect/nwc.db
- `DATABASE_URI`: a sqlite filename. Default: $XDG_DATA_HOME/albyhub/nwc.db
- `PORT`: the port on which the app should listen on (default: 8080)
- `WORK_DIR`: directory to store NWC data files. Default: $XDG_DATA_HOME/nostr-wallet-connect
- `WORK_DIR`: directory to store NWC data files. Default: $XDG_DATA_HOME/albyhub
- `LOG_LEVEL`: log level for the application. Higher is more verbose. Default: 4 (info)

### LND Backend parameters
Expand Down Expand Up @@ -179,9 +181,9 @@ Create an OAuth client at the [Alby Developer Portal](https://getalby.com/develo

Follow the steps to integrate Mutinynet with your NWC Next setup:

1. Configure your environment with the [Mutinynet LDK parameters](https://github.com/getAlby/nostr-wallet-connect-next#mutinynet)
1. Configure your environment with the [Mutinynet LDK parameters](https://github.com/getAlby/hub#mutinynet)

2. Proceed as described in the [Development](https://github.com/getAlby/nostr-wallet-connect-next#Development) section to run the frontend and backend
2. Proceed as described in the [Development](https://github.com/getAlby/hub#Development) section to run the frontend and backend

3. During onboarding, after setting your password and authorizing via Alby OAuth, you'll be directed to `/onboarding/lightning/migrate-alby`. Click "Skip For Now" to access your wallet interface

Expand Down Expand Up @@ -332,11 +334,11 @@ Run NWC on your own node!

### Digital Ocean

[![Deploy to DO](https://www.deploytodo.com/do-btn-blue.svg)](https://cloud.digitalocean.com/apps/new?repo=https://github.com/getAlby/nostr-wallet-connect-next/tree/master)
[![Deploy to DO](https://www.deploytodo.com/do-btn-blue.svg)](https://cloud.digitalocean.com/apps/new?repo=https://github.com/getAlby/hub/tree/master)

### Render

[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/getAlby/nostr-wallet-connect-next)
[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/getAlby/hub)

### Fly

Expand Down Expand Up @@ -378,10 +380,16 @@ LDK logs:

_Tested on Linux only_

`docker run -v ~/.local/share/alby-nwc:/data -e WORK_DIR='/data' -p 8080:8080 ghcr.io/getalby/nostr-wallet-connect-next:latest`
`docker run -v ~/.local/share/albyhub:/data -e WORK_DIR='/data' -p 8080:8080 ghcr.io/getalby/hub:latest`

#### From Source

_Tested on Linux only_

`docker run -v ~/.local/share/alby-nwc:/data -e WORK_DIR='/data' -p 8080:8080 $(docker build -q .)`
##### Docker Compose

`docker compose up`

##### Manually

`docker run -v ~/.local/share/albyhub:/data -e WORK_DIR='/data' -p 8080:8080 $(docker build -q .)`
31 changes: 17 additions & 14 deletions alby/alby_oauth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import (
"golang.org/x/oauth2"
"gorm.io/gorm"

"github.com/getAlby/nostr-wallet-connect/config"
"github.com/getAlby/nostr-wallet-connect/db"
"github.com/getAlby/nostr-wallet-connect/events"
"github.com/getAlby/nostr-wallet-connect/lnclient"
"github.com/getAlby/nostr-wallet-connect/logger"
nip47 "github.com/getAlby/nostr-wallet-connect/nip47/models"
"github.com/getAlby/nostr-wallet-connect/service/keys"
"github.com/getAlby/nostr-wallet-connect/transactions"
"github.com/getAlby/hub/config"
"github.com/getAlby/hub/db"
"github.com/getAlby/hub/events"
"github.com/getAlby/hub/lnclient"
"github.com/getAlby/hub/logger"
nip47 "github.com/getAlby/hub/nip47/models"
"github.com/getAlby/hub/service/keys"
"github.com/getAlby/hub/transactions"
)

type albyOAuthService struct {
Expand Down Expand Up @@ -259,15 +259,18 @@ func (svc *albyOAuthService) DrainSharedWallet(ctx context.Context, lnClient lnc
return err
}

amount := int64(math.Floor(
float64(balance.Balance)*1000* // Alby shared node balance in sats
(1-8/1000)* // Alby service fee (0.8%)
0.99)) - // Maximum potential routing fees (1%)
10000 // Alby fee reserve (10 sats)
balanceSat := float64(balance.Balance)

if amount < 1000 {
amountSat := int64(math.Floor(
balanceSat- // Alby shared node balance in sats
(balanceSat*(8/1000))- // Alby service fee (0.8%)
(balanceSat*0.01))) - // Maximum potential routing fees (1%)
10 // Alby fee reserve (10 sats)

if amountSat < 1 {
return errors.New("Not enough balance remaining")
}
amount := amountSat * 1000

logger.Logger.WithField("amount", amount).WithError(err).Error("Draining Alby shared wallet funds")

Expand Down
5 changes: 3 additions & 2 deletions alby/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package alby
import (
"context"

"github.com/getAlby/nostr-wallet-connect/events"
"github.com/getAlby/nostr-wallet-connect/lnclient"
"github.com/getAlby/hub/events"
"github.com/getAlby/hub/lnclient"
)

type AlbyOAuthService interface {
Expand Down Expand Up @@ -52,6 +52,7 @@ type ChannelPeerSuggestion struct {
Pubkey string `json:"pubkey"`
Host string `json:"host"`
MinimumChannelSize uint64 `json:"minimumChannelSize"`
MaximumChannelSize uint64 `json:"maximumChannelSize"`
Name string `json:"name"`
Image string `json:"image"`
BrokenLspUrl string `json:"lsp_url"`
Expand Down
22 changes: 11 additions & 11 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"

"github.com/getAlby/nostr-wallet-connect/alby"
"github.com/getAlby/nostr-wallet-connect/config"
"github.com/getAlby/nostr-wallet-connect/db"
"github.com/getAlby/nostr-wallet-connect/events"
"github.com/getAlby/nostr-wallet-connect/lnclient"
"github.com/getAlby/nostr-wallet-connect/logger"
permissions "github.com/getAlby/nostr-wallet-connect/nip47/permissions"
"github.com/getAlby/nostr-wallet-connect/service"
"github.com/getAlby/nostr-wallet-connect/service/keys"
"github.com/getAlby/nostr-wallet-connect/utils"
"github.com/getAlby/nostr-wallet-connect/version"
"github.com/getAlby/hub/alby"
"github.com/getAlby/hub/config"
"github.com/getAlby/hub/db"
"github.com/getAlby/hub/events"
"github.com/getAlby/hub/lnclient"
"github.com/getAlby/hub/logger"
permissions "github.com/getAlby/hub/nip47/permissions"
"github.com/getAlby/hub/service"
"github.com/getAlby/hub/service/keys"
"github.com/getAlby/hub/utils"
"github.com/getAlby/hub/version"
)

type api struct {
Expand Down
6 changes: 3 additions & 3 deletions api/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"crypto/rand"
"crypto/sha256"

"github.com/getAlby/nostr-wallet-connect/db"
"github.com/getAlby/nostr-wallet-connect/logger"
"github.com/getAlby/nostr-wallet-connect/utils"
"github.com/getAlby/hub/db"
"github.com/getAlby/hub/logger"
"github.com/getAlby/hub/utils"
"golang.org/x/crypto/pbkdf2"
)

Expand Down
2 changes: 1 addition & 1 deletion api/esplora.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
"time"

"github.com/getAlby/nostr-wallet-connect/logger"
"github.com/getAlby/hub/logger"
"github.com/sirupsen/logrus"
)

Expand Down
8 changes: 4 additions & 4 deletions api/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"strings"
"time"

"github.com/getAlby/nostr-wallet-connect/lnclient"
"github.com/getAlby/nostr-wallet-connect/logger"
"github.com/getAlby/nostr-wallet-connect/lsp"
"github.com/getAlby/nostr-wallet-connect/utils"
"github.com/getAlby/hub/lnclient"
"github.com/getAlby/hub/logger"
"github.com/getAlby/hub/lsp"
"github.com/getAlby/hub/utils"
decodepay "github.com/nbd-wtf/ln-decodepay"
"github.com/sirupsen/logrus"
)
Expand Down
8 changes: 4 additions & 4 deletions api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"io"
"time"

"github.com/getAlby/nostr-wallet-connect/alby"
"github.com/getAlby/nostr-wallet-connect/db"
"github.com/getAlby/nostr-wallet-connect/lnclient"
"github.com/getAlby/hub/alby"
"github.com/getAlby/hub/db"
"github.com/getAlby/hub/lnclient"
)

type API interface {
Expand All @@ -34,7 +34,7 @@ type API interface {
SignMessage(ctx context.Context, message string) (*SignMessageResponse, error)
RedeemOnchainFunds(ctx context.Context, toAddress string) (*RedeemOnchainFundsResponse, error)
GetBalances(ctx context.Context) (*BalancesResponse, error)
ListTransactions(ctx context.Context) (*ListTransactionsResponse, error)
ListTransactions(ctx context.Context, limit uint64, offset uint64) (*ListTransactionsResponse, error)
SendPayment(ctx context.Context, invoice string) (*SendPaymentResponse, error)
CreateInvoice(ctx context.Context, amount int64, description string) (*MakeInvoiceResponse, error)
LookupInvoice(ctx context.Context, paymentHash string) (*LookupInvoiceResponse, error)
Expand Down
6 changes: 3 additions & 3 deletions api/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"time"

"github.com/getAlby/nostr-wallet-connect/transactions"
"github.com/getAlby/hub/transactions"
)

func (api *api) CreateInvoice(ctx context.Context, amount int64, description string) (*MakeInvoiceResponse, error) {
Expand All @@ -31,11 +31,11 @@ func (api *api) LookupInvoice(ctx context.Context, paymentHash string) (*LookupI
}

// TODO: accept offset, limit params for pagination
func (api *api) ListTransactions(ctx context.Context) (*ListTransactionsResponse, error) {
func (api *api) ListTransactions(ctx context.Context, limit uint64, offset uint64) (*ListTransactionsResponse, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
transactions, err := api.svc.GetTransactionsService().ListTransactions(ctx, 0, 0, 20, 0, false, "", api.svc.GetLNClient())
transactions, err := api.svc.GetTransactionsService().ListTransactions(ctx, 0, 0, limit, offset, false, "", api.svc.GetLNClient())
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"time"

echologrus "github.com/davrux/echo-logrus/v4"
"github.com/getAlby/nostr-wallet-connect/http"
"github.com/getAlby/nostr-wallet-connect/logger"
"github.com/getAlby/nostr-wallet-connect/service"
"github.com/getAlby/hub/http"
"github.com/getAlby/hub/logger"
"github.com/getAlby/hub/service"
"github.com/labstack/echo/v4"
log "github.com/sirupsen/logrus"
)
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"
"os"

"github.com/getAlby/nostr-wallet-connect/db"
"github.com/getAlby/nostr-wallet-connect/logger"
"github.com/getAlby/hub/db"
"github.com/getAlby/hub/logger"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
Expand Down
2 changes: 1 addition & 1 deletion config/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type AppConfig struct {
CookieSecret string `envconfig:"COOKIE_SECRET"`
LogLevel string `envconfig:"LOG_LEVEL"`
LDKNetwork string `envconfig:"LDK_NETWORK" default:"bitcoin"`
LDKEsploraServer string `envconfig:"LDK_ESPLORA_SERVER" default:"https://electrs.albylabs.com"` // TODO: remove LDK prefix
LDKEsploraServer string `envconfig:"LDK_ESPLORA_SERVER" default:"https://electrs.getalby.com"` // TODO: remove LDK prefix
LDKGossipSource string `envconfig:"LDK_GOSSIP_SOURCE"`
LDKLogLevel string `envconfig:"LDK_LOG_LEVEL"`
MempoolApi string `envconfig:"MEMPOOL_API" default:"https://mempool.space/api"`
Expand Down
4 changes: 2 additions & 2 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package db
import (
"fmt"

"github.com/getAlby/nostr-wallet-connect/db/migrations"
"github.com/getAlby/nostr-wallet-connect/logger"
"github.com/getAlby/hub/db/migrations"
"github.com/getAlby/hub/logger"
"github.com/glebarez/sqlite"
"gorm.io/gorm"
)
Expand Down
4 changes: 2 additions & 2 deletions db/db_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

"github.com/getAlby/nostr-wallet-connect/events"
"github.com/getAlby/nostr-wallet-connect/logger"
"github.com/getAlby/hub/events"
"github.com/getAlby/hub/logger"
"github.com/nbd-wtf/go-nostr"
"gorm.io/gorm"
)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
albyhub:
platform: linux/amd64
container_name: albyhub
image: ghcr.io/getalby/nostr-wallet-connect-next:latest
image: ghcr.io/getalby/hub:latest
volumes:
- ./albyhub-data:/data
ports:
Expand Down
Loading

0 comments on commit d7b163d

Please sign in to comment.