Skip to content

Commit

Permalink
feat: add strike backend
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Dec 12, 2023
1 parent 9b70e8a commit bea0431
Show file tree
Hide file tree
Showing 11 changed files with 618 additions and 54 deletions.
15 changes: 15 additions & 0 deletions .env.alby
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
DATABASE_URI=postgresql://user@localhost:5432/nostrwalletconnect_lnd?sslmode=disable
NOSTR_PRIVKEY=
LN_BACKEND_TYPE=ALBY

CLIENT_ID=
CLIENT_SECRET=
OAUTH_AUTH_URL=https://getalby.com/oauth
OAUTH_API_URL=https://api.getalby.com
OAUTH_TOKEN_URL=https://api.getalby.com/oauth/token
OAUTH_REDIRECT_URL=http://nwc.example.com:8080/alby/callback

COOKIE_SECRET=secretsecret
COOKIE_DOMAIN=.example.com
RELAY=wss://relay.getalby.com/v1
PORT=8080
9 changes: 9 additions & 0 deletions .env.lnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DATABASE_URI=postgresql://user@localhost:5432/nostrwalletconnect_lnd?sslmode=disable
NOSTR_PRIVKEY=
LND_ADDRESS=rpc.lnd3.regtest.getalby.com:443
LND_MACAROON_FILE=testnet_lnd3.macaroon
LN_BACKEND_TYPE=LND
COOKIE_SECRET=secretsecret
COOKIE_DOMAIN=.example.com
RELAY=wss://relay.getalby.com/v1
PORT=8080
15 changes: 15 additions & 0 deletions .env.strike
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
DATABASE_URI=postgresql://user@localhost:5432/nostrwalletconnect_lnd?sslmode=disable
NOSTR_PRIVKEY=
LN_BACKEND_TYPE=STRIKE

CLIENT_ID=
CLIENT_SECRET=
OAUTH_AUTH_URL=https://auth.strike.me/connect/authorize
OAUTH_API_URL=https://api.strike.me/v1
OAUTH_TOKEN_URL=https://auth.strike.me/connect/token
OAUTH_REDIRECT_URL=http://localhost:3000/api/auth/callback/strike

COOKIE_SECRET=secretsecret
COOKIE_DOMAIN=.example.com
RELAY=wss://relay.getalby.com/v1
PORT=3000
14 changes: 7 additions & 7 deletions alby.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type AlbyOAuthService struct {

func NewAlbyOauthService(svc *Service, e *echo.Echo) (result *AlbyOAuthService, err error) {
conf := &oauth2.Config{
ClientID: svc.cfg.AlbyClientId,
ClientSecret: svc.cfg.AlbyClientSecret,
ClientID: svc.cfg.ClientId,
ClientSecret: svc.cfg.ClientSecret,
//Todo: do we really need all these permissions?
Scopes: []string{"account:read", "payments:send", "invoices:read", "transactions:read", "invoices:create", "balance:read"},
Endpoint: oauth2.Endpoint{
Expand Down Expand Up @@ -133,7 +133,7 @@ func (svc *AlbyOAuthService) MakeInvoice(ctx context.Context, senderPubkey strin
err = json.NewEncoder(body).Encode(payload)

// TODO: move to a shared function
req, err := http.NewRequest("POST", fmt.Sprintf("%s/invoices", svc.cfg.AlbyAPIURL), body)
req, err := http.NewRequest("POST", fmt.Sprintf("%s/invoices", svc.cfg.OAuthAPIURL), body)
if err != nil {
svc.Logger.WithError(err).Error("Error creating request /invoices")
return "", "", err
Expand Down Expand Up @@ -220,7 +220,7 @@ func (svc *AlbyOAuthService) LookupInvoice(ctx context.Context, senderPubkey str
body := bytes.NewBuffer([]byte{})

// TODO: move to a shared function
req, err := http.NewRequest("GET", fmt.Sprintf("%s/invoices/%s", svc.cfg.AlbyAPIURL, paymentHash), body)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/invoices/%s", svc.cfg.OAuthAPIURL, paymentHash), body)
if err != nil {
svc.Logger.WithError(err).Errorf("Error creating request /invoices/%s", paymentHash)
return "", false, err
Expand Down Expand Up @@ -286,7 +286,7 @@ func (svc *AlbyOAuthService) GetBalance(ctx context.Context, senderPubkey string
}
client := svc.oauthConf.Client(ctx, tok)

req, err := http.NewRequest("GET", fmt.Sprintf("%s/balance", svc.cfg.AlbyAPIURL), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/balance", svc.cfg.OAuthAPIURL), nil)
if err != nil {
svc.Logger.WithError(err).Error("Error creating request /balance")
return 0, err
Expand Down Expand Up @@ -359,7 +359,7 @@ func (svc *AlbyOAuthService) SendPaymentSync(ctx context.Context, senderPubkey,
}
err = json.NewEncoder(body).Encode(payload)

req, err := http.NewRequest("POST", fmt.Sprintf("%s/payments/bolt11", svc.cfg.AlbyAPIURL), body)
req, err := http.NewRequest("POST", fmt.Sprintf("%s/payments/bolt11", svc.cfg.OAuthAPIURL), body)
if err != nil {
svc.Logger.WithError(err).Error("Error creating request /payments/bolt11")
return "", err
Expand Down Expand Up @@ -434,7 +434,7 @@ func (svc *AlbyOAuthService) CallbackHandler(c echo.Context) error {
}
client := svc.oauthConf.Client(c.Request().Context(), tok)

req, err := http.NewRequest("GET", fmt.Sprintf("%s/user/me", svc.cfg.AlbyAPIURL), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/user/me", svc.cfg.OAuthAPIURL), nil)
if err != nil {
svc.Logger.WithError(err).Error("Error creating request /me")
return err
Expand Down
17 changes: 9 additions & 8 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main

const (
AlbyBackendType = "ALBY"
LNDBackendType = "LND"
CookieName = "alby_nwc_session"
AlbyBackendType = "ALBY"
LNDBackendType = "LND"
StrikeBackendType = "STRIKE"
CookieName = "alby_nwc_session"
)

type Config struct {
Expand All @@ -17,12 +18,12 @@ type Config struct {
LNDAddress string `envconfig:"LND_ADDRESS"`
LNDCertFile string `envconfig:"LND_CERT_FILE"`
LNDMacaroonFile string `envconfig:"LND_MACAROON_FILE"`
AlbyAPIURL string `envconfig:"ALBY_API_URL" default:"https://api.getalby.com"`
AlbyClientId string `envconfig:"ALBY_CLIENT_ID"`
AlbyClientSecret string `envconfig:"ALBY_CLIENT_SECRET"`
ClientId string `envconfig:"CLIENT_ID"`
ClientSecret string `envconfig:"CLIENT_SECRET"`
OAuthAPIURL string `envconfig:"OAUTH_API_URL"`
OAuthRedirectUrl string `envconfig:"OAUTH_REDIRECT_URL"`
OAuthAuthUrl string `envconfig:"OAUTH_AUTH_URL" default:"https://getalby.com/oauth"`
OAuthTokenUrl string `envconfig:"OAUTH_TOKEN_URL" default:"https://api.getalby.com/oauth/token"`
OAuthAuthUrl string `envconfig:"OAUTH_AUTH_URL"`
OAuthTokenUrl string `envconfig:"OAUTH_TOKEN_URL"`
Port string `envconfig:"PORT" default:"8080"`
DatabaseUri string `envconfig:"DATABASE_URI" default:"nostr-wallet-connect.db"`
DatabaseMaxConns int `envconfig:"DATABASE_MAX_CONNS" default:"10"`
Expand Down
1 change: 1 addition & 0 deletions echo_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (svc *Service) RegisterSharedRoutes(e *echo.Echo) {
templates["about.html"] = template.Must(template.ParseFS(embeddedViews, "views/about.html", "views/layout.html"))
templates["404.html"] = template.Must(template.ParseFS(embeddedViews, "views/404.html", "views/layout.html"))
templates["lnd/index.html"] = template.Must(template.ParseFS(embeddedViews, "views/backends/lnd/index.html", "views/layout.html"))
templates["strike/index.html"] = template.Must(template.ParseFS(embeddedViews, "views/backends/strike/index.html", "views/layout.html"))
e.Renderer = &TemplateRegistry{
templates: templates,
}
Expand Down
18 changes: 8 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ go 1.20

require (
github.com/davrux/echo-logrus/v4 v4.0.3
github.com/go-gormigrate/gormigrate/v2 v2.1.1
github.com/gorilla/sessions v1.2.1
github.com/labstack/echo-contrib v0.14.1
github.com/labstack/echo/v4 v4.10.2
github.com/nbd-wtf/go-nostr v0.25.5
github.com/nbd-wtf/ln-decodepay v1.11.1
github.com/stretchr/testify v1.8.2
golang.org/x/oauth2 v0.4.0
golang.org/x/oauth2 v0.15.0
google.golang.org/grpc v1.53.0
gopkg.in/DataDog/dd-trace-go.v1 v1.47.0
gopkg.in/macaroon.v2 v2.1.0
Expand Down Expand Up @@ -55,7 +56,6 @@ require (
github.com/fergusstrange/embedded-postgres v1.19.0 // indirect
github.com/glebarez/go-sqlite v1.20.3 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-gormigrate/gormigrate/v2 v2.1.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-macaroon-bakery/macaroonpb v1.0.0 // indirect
Expand Down Expand Up @@ -160,18 +160,18 @@ require (
go.uber.org/zap v1.24.0 // indirect
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230113154510-dbe35b8444a5 // indirect
google.golang.org/protobuf v1.29.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/errgo.v1 v1.0.1 // indirect
gopkg.in/macaroon-bakery.v2 v2.3.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
Expand All @@ -186,7 +186,6 @@ require (
)

require (
github.com/SaveTheRbtz/generic-sync-map-go v0.0.0-20220414055132-a37292614db8 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
Expand All @@ -199,7 +198,6 @@ require (
github.com/lightningnetwork/lnd v0.15.5-beta.rc2
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/sirupsen/logrus v1.9.0
github.com/valyala/fastjson v1.6.3 // indirect
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 // indirect
gorm.io/driver/postgres v1.5.2
)
Loading

0 comments on commit bea0431

Please sign in to comment.