Add nostr nip-05 registration with lnd invoices #1
2 changed files with 34 additions and 2 deletions
12
html/nostr_qr_response.html
Normal file
12
html/nostr_qr_response.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<p>Nostr NIP-05 {{ .RequestKey }}</p><br>
|
||||
<img src="data:image/png;base64,{{.QRCode}}"/><br>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -33,6 +34,11 @@ type NostrRequest struct {
|
|||
Relays []string `json:"relays,omitempty"`
|
||||
}
|
||||
|
||||
type NostrResponse struct {
|
||||
RequestKey string `json:"request_key"`
|
||||
QRCode string `json:"QRCode"`
|
||||
}
|
||||
|
||||
func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.TODO()
|
||||
l := logger.Get()
|
||||
|
@ -99,6 +105,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// generate qr png
|
||||
png, err := qrcode.Encode(paymentReq, qrcode.Medium, 256)
|
||||
pngB64 := b64.StdEncoding.EncodeToString(png)
|
||||
|
||||
// write request to redis
|
||||
err = redisCli.Set(ctx, rKey, enc, 15*time.Minute).Err()
|
||||
|
@ -107,9 +114,22 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// return qr code
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
response := NostrResponse{
|
||||
RequestKey: rKey,
|
||||
QRCode: pngB64,
|
||||
}
|
||||
|
||||
tmplt, err := template.ParseFiles("html/nostr_qr_response.html")
|
||||
if err != nil {
|
||||
l.Error().Msg("unable to parse template")
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(png)
|
||||
err = tmplt.Execute(w, response)
|
||||
if err != nil {
|
||||
l.Error().Msg("unable to connect to render template")
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue