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

Commit

Permalink
Merge branch 'refs/heads/master' into release-wails
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/wails2.yaml
  • Loading branch information
Roman Dmitrienko committed Jun 16, 2024
2 parents baa7f8b + a7ddb6d commit 7d82a66
Show file tree
Hide file tree
Showing 101 changed files with 3,202 additions and 1,350 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Code quality - linting and typechecking

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize]

jobs:
linting:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20.x
cache: "yarn"
cache-dependency-path: frontend/yarn.lock

- run: yarn install
- run: yarn prepare:http

- name: Linting
run: yarn lint:js

- name: Prettier
run: yarn format

- name: Typechecking
run: yarn tsc:compile
54 changes: 43 additions & 11 deletions .github/workflows/wails2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ jobs:
strategy:
fail-fast: false
matrix:
build: [
{name: albyhub, platform: linux/amd64, os: ubuntu-20.04},
{name: albyhub, platform: windows/amd64, os: windows-2019},
{name: albyhub, platform: darwin/universal, os: macos-12}
]
build:
[
{ name: albyhub, platform: linux/amd64, os: ubuntu-20.04 },
{ name: albyhub, platform: windows/amd64, os: windows-2019 },
{ name: albyhub, platform: darwin/universal, os: macos-12 },
]
runs-on: ${{ matrix.build.os }}
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -47,7 +48,7 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: '20.x'
node-version: "20.x"

- name: Install Wails
run: go install github.com/wailsapp/wails/v2/cmd/[email protected]
Expand All @@ -60,7 +61,9 @@ jobs:

- name: Install macOS Wails deps
if: runner.os == 'macOS'
run: brew install mitchellh/gon/gon
run: |
brew install create-dmg
brew install Bearer/tap/gon
shell: bash

- name: Wails Doctor
Expand All @@ -84,19 +87,28 @@ jobs:

- name: Build App
if: runner.os == 'macOS'
run: wails build --platform darwin/universal -webview2 download -o ${{ matrix.build.name }} -tags "wails"
run: wails build --platform darwin/universal -webview2 embed -o ${{ matrix.build.name }} -tags "wails"
shell: bash

- name: Build App
if: runner.os == 'Linux'
run: wails build --platform linux/amd64 -webview2 download -o ${{ matrix.build.name }} -tags "wails"
run: wails build --platform linux/amd64 -webview2 embed -o ${{ matrix.build.name }} -tags "wails"
shell: bash

- name: Build Windows App
if: runner.os == 'Windows'
run: wails build --platform windows/amd64 -webview2 download -o ${{ matrix.build.name }}.exe -tags "wails"
run: wails build --platform windows/amd64 -webview2 embed -o ${{ matrix.build.name }}.exe -tags "wails"
shell: bash

- name: Import Code-Signing Certificates for macOS
if: runner.os == 'macOS'
uses: Apple-Actions/import-codesign-certs@v1
with:
# The certificates in a PKCS12 file encoded as a base64 string
p12-file-base64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }}
# The password used to import the PKCS12 file.
p12-password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }}

- name: Copy DLLs to the output directory
if: runner.os == 'Windows'
run: |
Expand Down Expand Up @@ -155,14 +167,34 @@ jobs:
rm -Rf ./build/bin/*
mv ./build/out/albyhub-${{runner.os}}.tar.bz2 ./build/bin/
- name: Sign the macOS binary
if: runner.os == 'macOS'
run: |
echo "Signing Package"
/usr/bin/codesign -s "Developer ID Application: Alby Inc." -f -v --deep --timestamp --options runtime --entitlements ./build/darwin/entitlements.plist ./build/bin/AlbyHub.app
env:
AC_USERNAME: ${{ secrets.APPLE_USERNAME }}
AC_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
AC_PROVIDER: ${{ secrets.APPLE_TEAM_ID }}

- name: Make DMG image for macOS
if: runner.os == 'macOS'
run: |
mkdir -p ./build/out
hdiutil create -volname "AlbyHub" -srcfolder ./build/bin/${{ matrix.build.name }}.app -ov -format UDZO ./build/out/albyhub-${{runner.os}}.dmg
create-dmg --volname "AlbyHub" --background "./build/darwin/dmgcover.png" --window-pos 200 120 --window-size 800 400 --icon-size 80 --icon "AlbyHub.app" 200 160 --hide-extension "AlbyHub.app" --app-drop-link 600 160 "./build/out/albyhub-${{runner.os}}.dmg" "./build/bin/${{ matrix.build.name }}.app"
rm -Rf ./build/bin/*
mv ./build/out/albyhub-${{runner.os}}.dmg ./build/bin/
- name: Notarize the DMG image
if: runner.os == 'macOS'
run: |
echo "Notarizing Zip Files"
gon -log-level=info -log-json ./build/darwin/gon-notarize.json
env:
AC_USERNAME: ${{ secrets.APPLE_USERNAME }}
AC_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
AC_PROVIDER: ${{ secrets.APPLE_TEAM_ID }}

- name: Make Windows ZIP archive
if: runner.os == 'Windows'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ frontend/node_modules
frontend/wailsjs
package.json.md5

build
build/bin

*.log

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Follow the steps to integrate Mutinynet with your NWC Next setup:

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

4. Navigate to `channels/onchain/new-address`, copy your On-Chain Address, then visit the [Mutinynet Faucet](https://faucet.mutinynet.com/) to deposit sats. Ensure the transaction confirms on [mempool.space](https://mutinynet.com/)
4. Navigate to `channels/onchain/deposit-bitcoin`, copy your On-Chain Address, then visit the [Mutinynet Faucet](https://faucet.mutinynet.com/) to deposit sats. Ensure the transaction confirms on [mempool.space](https://mutinynet.com/)

5. Your On-chain balance will update under `/channels`

Expand Down
23 changes: 13 additions & 10 deletions alby/alby_oauth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,27 @@ func (svc *albyOAuthService) CallbackHandler(ctx context.Context, code string) e
}
svc.saveToken(token)

me, err := svc.GetMe(ctx)
if err != nil {
svc.logger.WithError(err).Error("Failed to fetch user me")
// remove token so user can retry
svc.config.SetUpdate(accessTokenKey, "", "")
return err
}

existingUserIdentifier, err := svc.GetUserIdentifier()
if err != nil {
svc.logger.WithError(err).Error("Failed to get alby user identifier")
return err
}

// setup Alby account on first time login
// save the user's alby account ID on first time login
if existingUserIdentifier == "" {
// fetch and save the user's alby account ID. This cannot be changed.
me, err := svc.GetMe(ctx)
if err != nil {
svc.logger.WithError(err).Error("Failed to fetch user me")
// remove token so user can retry
svc.config.SetUpdate(accessTokenKey, me.Identifier, "")
return err
}

svc.config.SetUpdate(userIdentifierKey, me.Identifier, "")
} else if me.Identifier != existingUserIdentifier {
// remove token so user can retry with correct account
svc.config.SetUpdate(accessTokenKey, "", "")
return errors.New("Alby Hub is connected to a different alby account. Please log out of your Alby Account at getalby.com and try again.")
}

return nil
Expand Down
60 changes: 53 additions & 7 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/getAlby/nostr-wallet-connect/alby"
"github.com/getAlby/nostr-wallet-connect/backup"
"github.com/getAlby/nostr-wallet-connect/config"
"github.com/getAlby/nostr-wallet-connect/db"
"github.com/getAlby/nostr-wallet-connect/lnclient"
"github.com/getAlby/nostr-wallet-connect/lsp"
Expand Down Expand Up @@ -375,17 +376,57 @@ func (api *api) CloseChannel(ctx context.Context, peerId, channelId string, forc
})
}

func (api *api) GetNewOnchainAddress(ctx context.Context) (*NewOnchainAddressResponse, error) {
func (api *api) GetNewOnchainAddress(ctx context.Context) (string, error) {
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
return "", errors.New("LNClient not started")
}
address, err := api.svc.GetLNClient().GetNewOnchainAddress(ctx)
if err != nil {
return nil, err
return "", err
}
return &NewOnchainAddressResponse{
Address: address,
}, nil

api.svc.GetConfig().SetUpdate(config.OnchainAddressKey, address, "")

return address, nil
}

func (api *api) GetUnusedOnchainAddress(ctx context.Context) (string, error) {
if api.svc.GetLNClient() == nil {
return "", errors.New("LNClient not started")
}

currentAddress, err := api.svc.GetConfig().Get(config.OnchainAddressKey, "")
if err != nil {
api.logger.WithError(err).Error("Failed to get current address from config")
return "", err
}

if currentAddress != "" {
// check if address has any transactions
response, err := api.RequestEsploraApi("/address/" + currentAddress + "/txs")
if err != nil {
api.logger.WithError(err).Error("Failed to get current address transactions")
return currentAddress, nil
}

transactions, ok := response.([]interface{})
if !ok {
api.logger.WithField("response", response).Error("Failed to cast esplora address txs response", response)
return currentAddress, nil
}

if len(transactions) == 0 {
// address has not been used yet
return currentAddress, nil
}
}

newAddress, err := api.GetNewOnchainAddress(ctx)
if err != nil {
api.logger.WithError(err).Error("Failed to retrieve new onchain address")
return "", err
}
return newAddress, nil
}

func (api *api) SignMessage(ctx context.Context, message string) (*SignMessageResponse, error) {
Expand Down Expand Up @@ -426,6 +467,7 @@ func (api *api) GetBalances(ctx context.Context) (*BalancesResponse, error) {
return balances, nil
}

// TODO: remove dependency on this endpoint
func (api *api) RequestMempoolApi(endpoint string) (interface{}, error) {
url := api.svc.GetConfig().GetEnv().MempoolApi + endpoint

Expand Down Expand Up @@ -558,12 +600,16 @@ func (api *api) Setup(ctx context.Context, setupRequest *SetupRequest) error {
}

if setupRequest.PhoenixdAddress != "" {
api.svc.GetConfig().SetUpdate("PhoenixAddress", setupRequest.PhoenixdAddress, setupRequest.UnlockPassword)
api.svc.GetConfig().SetUpdate("PhoenixdAddress", setupRequest.PhoenixdAddress, setupRequest.UnlockPassword)
}
if setupRequest.PhoenixdAuthorization != "" {
api.svc.GetConfig().SetUpdate("PhoenixdAuthorization", setupRequest.PhoenixdAuthorization, setupRequest.UnlockPassword)
}

if setupRequest.CashuMintUrl != "" {
api.svc.GetConfig().SetUpdate("CashuMintUrl", setupRequest.CashuMintUrl, setupRequest.UnlockPassword)
}

return nil
}

Expand Down
56 changes: 56 additions & 0 deletions api/esplora.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package api

import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"time"

"github.com/sirupsen/logrus"
)

func (api *api) RequestEsploraApi(endpoint string) (interface{}, error) {
url := api.svc.GetConfig().GetEnv().LDKEsploraServer + endpoint

client := http.Client{
Timeout: time.Second * 10,
}

req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
api.logger.WithError(err).WithFields(logrus.Fields{
"url": url,
}).Error("Failed to create http request")
return nil, err
}

res, err := client.Do(req)
if err != nil {
api.logger.WithError(err).WithFields(logrus.Fields{
"url": url,
}).Error("Failed to send request")
return nil, err
}

defer res.Body.Close()

body, readErr := io.ReadAll(res.Body)
if readErr != nil {
api.logger.WithError(err).WithFields(logrus.Fields{
"url": url,
}).Error("Failed to read response body")
return nil, errors.New("failed to read response body")
}

var jsonContent interface{}
jsonErr := json.Unmarshal(body, &jsonContent)
if jsonErr != nil {
api.logger.WithError(jsonErr).WithFields(logrus.Fields{
"url": url,
}).Error("Failed to deserialize json")
return nil, fmt.Errorf("failed to deserialize json %s %s", url, string(body))
}
return jsonContent, nil
}
9 changes: 3 additions & 6 deletions api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type API interface {
DisconnectPeer(ctx context.Context, peerId string) error
OpenChannel(ctx context.Context, openChannelRequest *OpenChannelRequest) (*OpenChannelResponse, error)
CloseChannel(ctx context.Context, peerId, channelId string, force bool) (*CloseChannelResponse, error)
GetNewOnchainAddress(ctx context.Context) (*NewOnchainAddressResponse, error)
GetNewOnchainAddress(ctx context.Context) (string, error)
GetUnusedOnchainAddress(ctx context.Context) (string, error)
SignMessage(ctx context.Context, message string) (*SignMessageResponse, error)
RedeemOnchainFunds(ctx context.Context, toAddress string) (*RedeemOnchainFundsResponse, error)
GetBalances(ctx context.Context) (*BalancesResponse, error)
Expand Down Expand Up @@ -98,7 +99,7 @@ type BackupReminderRequest struct {
}

type SetupRequest struct {
LNBackendType string `json:"backendType"`
LNBackendType string `json:"backendType"`
UnlockPassword string `json:"unlockPassword"`

// Breez / Greenlight
Expand Down Expand Up @@ -174,10 +175,6 @@ type RedeemOnchainFundsResponse struct {
type OnchainBalanceResponse = lnclient.OnchainBalanceResponse
type BalancesResponse = lnclient.BalancesResponse

type NewOnchainAddressResponse struct {
Address string `json:"address"`
}

// debug api
type SendPaymentProbesRequest struct {
Invoice string `json:"invoice"`
Expand Down
Binary file modified appicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7d82a66

Please sign in to comment.