Skip to content

Commit

Permalink
Merge branch 'master' into task-permissions-revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jul 11, 2024
2 parents ee2ab64 + 1122f73 commit c82f53e
Show file tree
Hide file tree
Showing 140 changed files with 2,086 additions and 1,031 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
10 changes: 5 additions & 5 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 All @@ -65,7 +65,7 @@ jobs:
node-version: "20.x"

- name: Install Wails
run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.8.2
run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.9.1
shell: bash

- name: Install Linux Wails deps
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 .)`
47 changes: 30 additions & 17 deletions alby/alby_oauth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ 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/hub/config"
"github.com/getAlby/hub/db"
"github.com/getAlby/hub/events"
"github.com/getAlby/hub/lnclient"
"github.com/getAlby/hub/logger"
"github.com/getAlby/hub/nip47/permissions"
"github.com/getAlby/hub/service/keys"
)

type albyOAuthService struct {
Expand Down Expand Up @@ -258,15 +258,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.0/1000.0))- // 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 Expand Up @@ -376,20 +379,30 @@ func (svc *albyOAuthService) GetAuthUrl() string {
return svc.oauthConf.AuthCodeURL("unused")
}

func (svc *albyOAuthService) LinkAccount(ctx context.Context, lnClient lnclient.LNClient) error {
func (svc *albyOAuthService) LinkAccount(ctx context.Context, lnClient lnclient.LNClient, budget uint64, renewal string) error {
connectionPubkey, err := svc.createAlbyAccountNWCNode(ctx)
if err != nil {
logger.Logger.WithError(err).Error("Failed to create alby account nwc node")
return err
}

scopes, err := permissions.RequestMethodsToScopes(lnClient.GetSupportedNIP47Methods())
if err != nil {
logger.Logger.WithError(err).Error("Failed to get scopes from LNClient request methods")
return err
}
notificationTypes := lnClient.GetSupportedNIP47NotificationTypes()
if len(notificationTypes) > 0 {
scopes = append(scopes, permissions.NOTIFICATIONS_SCOPE)
}

app, _, err := db.NewDBService(svc.db, svc.eventPublisher).CreateApp(
"getalby.com",
connectionPubkey,
1_000_000,
nip47.BUDGET_RENEWAL_MONTHLY,
budget,
renewal,
nil,
lnClient.GetSupportedNIP47Methods(),
scopes,
)

if err != nil {
Expand Down
32 changes: 21 additions & 11 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 All @@ -13,7 +13,7 @@ type AlbyOAuthService interface {
GetAuthUrl() string
GetUserIdentifier() (string, error)
IsConnected(ctx context.Context) bool
LinkAccount(ctx context.Context, lnClient lnclient.LNClient) error
LinkAccount(ctx context.Context, lnClient lnclient.LNClient, budget uint64, renewal string) error
CallbackHandler(ctx context.Context, code string) error
GetBalance(ctx context.Context) (*AlbyBalance, error)
GetMe(ctx context.Context) (*AlbyMe, error)
Expand All @@ -29,15 +29,24 @@ type AlbyPayRequest struct {
Invoice string `json:"invoice"`
}

type AlbyLinkAccountRequest struct {
Budget uint64 `json:"budget"`
Renewal string `json:"renewal"`
}

type AlbyMeHub struct {
LatestVersion string `json:"latest_version"`
}
type AlbyMe struct {
Identifier string `json:"identifier"`
NPub string `json:"nostr_pubkey"`
LightningAddress string `json:"lightning_address"`
Email string `json:"email"`
Name string `json:"name"`
Avatar string `json:"avatar"`
KeysendPubkey string `json:"keysend_pubkey"`
SharedNode bool `json:"shared_node"`
Identifier string `json:"identifier"`
NPub string `json:"nostr_pubkey"`
LightningAddress string `json:"lightning_address"`
Email string `json:"email"`
Name string `json:"name"`
Avatar string `json:"avatar"`
KeysendPubkey string `json:"keysend_pubkey"`
SharedNode bool `json:"shared_node"`
Hub AlbyMeHub `json:"hub"`
}

type AlbyBalance struct {
Expand All @@ -52,6 +61,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
28 changes: 13 additions & 15 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 Expand Up @@ -487,12 +487,11 @@ func (api *api) GetBalances(ctx context.Context) (*BalancesResponse, error) {
return balances, nil
}

// 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.GetLNClient().ListTransactions(ctx, 0, 0, 20, 0, false, "")
transactions, err := api.svc.GetLNClient().ListTransactions(ctx, 0, 0, limit, offset, false, "")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -581,7 +580,6 @@ func (api *api) GetInfo(ctx context.Context) (*InfoResponse, error) {
info.AlbyAuthUrl = api.albyOAuthSvc.GetAuthUrl()
info.OAuthRedirect = !api.cfg.GetEnv().IsDefaultClientId()
info.Version = version.Tag
info.LatestVersion = version.GetLatestReleaseTag()
albyUserIdentifier, err := api.albyOAuthSvc.GetUserIdentifier()
if err != nil {
logger.Logger.WithError(err).Error("Failed to get alby user identifier")
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
Loading

0 comments on commit c82f53e

Please sign in to comment.