diff --git a/Makefile b/Makefile index ac31083..9c366a0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -satdress: $(shell find . -name "*.go") +satdress: $(shell find . -name "*.go") index.html go.mod CC=$$(which musl-gcc) go build -ldflags='-s -w -linkmode external -extldflags "-static"' -o ./satdress deploy: satdress diff --git a/db.go b/db.go index adeb803..2ee3d2f 100644 --- a/db.go +++ b/db.go @@ -1,5 +1,16 @@ package main +import ( + "crypto/hmac" + "crypto/sha256" + "encoding/hex" + "encoding/json" + "errors" + "fmt" + + "github.com/cockroachdb/pebble" +) + type Params struct { Name string Kind string @@ -8,3 +19,45 @@ type Params struct { Pak string Waki string } + +func SaveName(name string, params *Params, providedPin string) (pin string, err error) { + key := []byte(name + "@" + s.Domain) + + mac := hmac.New(sha256.New, []byte(s.Secret)) + mac.Write(key) + pin = hex.EncodeToString(mac.Sum(nil)) + + if _, closer, err := db.Get(key); err == nil { + defer closer.Close() + if pin != providedPin { + return "", errors.New("name already exists! must provide pin.") + } + } + + // check if the given data works + if _, err := makeInvoice(params, 1000); err != nil { + return "", fmt.Errorf("couldn't make an invoice with the given data: %w", err) + } + + // save it + data, _ := json.Marshal(params) + if err := db.Set(key, data, pebble.Sync); err != nil { + return "", err + } + + return pin, nil +} + +func GetName(name string) (params *Params, err error) { + val, closer, err := db.Get([]byte(name)) + if err != nil { + return nil, err + } + defer closer.Close() + if err := json.Unmarshal(val, params); err != nil { + return nil, err + } + + params.Name = name + return params, nil +} diff --git a/go.mod b/go.mod index 79e4b07..8a3c7d1 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/fiatjaf/go-lnurl v1.4.0 github.com/fiatjaf/makeinvoice v1.2.3 github.com/gorilla/mux v1.8.0 + github.com/joho/godotenv v1.3.0 // indirect github.com/kelseyhightower/envconfig v1.4.0 github.com/lib/pq v1.10.2 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 diff --git a/go.sum b/go.sum index 487dbd6..b3fc4f7 100644 --- a/go.sum +++ b/go.sum @@ -203,6 +203,8 @@ github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad/go.mod h1:QPH04 github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/jrick/logrotate v1.0.0 h1:lQ1bL/n9mBNeIXoTUoYRlK4dHuNJVofX9oWqBtPnSzI= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= diff --git a/index.html b/index.html index 739580b..7fc258f 100644 --- a/index.html +++ b/index.html @@ -103,7 +103,17 @@ background-color: rgba(86, 46, 249, 0.85); } - .label { + .field { + display: flex; + flex-direction: column; + } + + .row { + display: flex; + flex-direction: row; + } + + label { margin: 0; font-size: 16px; font-weight: 600; @@ -147,11 +157,6 @@ background-color: #f3f3f3; } - label { - display: flex; - flex-direction: column; - } - .resources { display: flex; align-items: center; @@ -233,67 +238,79 @@