Add nostr nip-05 registration with lnd invoices #1

Merged
Asara merged 33 commits from nostr_lnd into main 2023-05-30 00:10:37 +00:00
3 changed files with 10 additions and 15 deletions
Showing only changes of commit 5b29025296 - Show all commits

View file

@ -37,21 +37,24 @@ func Request(rKey string) (string, error) {
return "", errors.New("internal server error")
}
info, err := lndCli.AddInvoice(ctx, &lnrpc.Invoice{
expiryInMin := int64(5)
expiryTime := time.Now().Local().Add(time.Minute * time.Duration(expiryInMin)).Unix()
invoice, err := lndCli.AddInvoice(ctx, &lnrpc.Invoice{
Memo: fmt.Sprintf("nostr addr %s", rKey),
Expiry: 1 * 60,
Expiry: expiryInMin * 60,
Value: addrFee,
})
if err != nil {
l.Fatal().Msg("unable to create lnd invoice")
return "", errors.New("internal server error")
}
rHash := hex.EncodeToString(info.RHash)
paymentReq := info.PaymentRequest
paymentReq := invoice.PaymentRequest
rHash := hex.EncodeToString(invoice.RHash)
// write lnd request to redis
redisCli := redis.LndRedisConn.Client
err = redisCli.Set(ctx, rKey, fmt.Sprintf("%s:%s", rHash, paymentReq), 15*time.Minute).Err()
err = redisCli.Set(ctx, rKey, fmt.Sprintf("%d:%s:%s", expiryTime, rHash, paymentReq), 0).Err()
if err != nil {
l.Error().Msg("unable to connect to redis when writing lnd request")
return "", errors.New("unable to make the request, please try again")

View file

@ -22,14 +22,7 @@ func main() {
if err != nil {
l.Fatal().Msg("unable to connect to redis")
}
/*
nostrTest := nostr.NostrRequest{
Name: "asara",
Key: "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6",
Hostname: "devvul.com",
}
nostr.AddNostrAddr(nostrTest)
*/
// matrix endpoints
l.Debug().Msg("enabling matrix server endpoint")
http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer)

View file

@ -9,7 +9,6 @@ import (
"html/template"
"net/http"
"strings"
"time"
"git.minhas.io/asara/well-goknown/lnd"
"git.minhas.io/asara/well-goknown/logger"
@ -108,7 +107,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
pngB64 := b64.StdEncoding.EncodeToString(png)
// write request to redis
err = redisCli.Set(ctx, rKey, enc, 15*time.Minute).Err()
err = redisCli.Set(ctx, rKey, enc, 0).Err()
if err != nil {
l.Error().Msg("unable to connect to redis")
}