test invoice has pin in its description.

fixes https://github.com/fiatjaf/satdress/issues/12
This commit is contained in:
fiatjaf 2021-08-28 09:50:17 -03:00
parent 8a659a98e6
commit efb41f6d6b
5 changed files with 42 additions and 18 deletions

4
db.go
View File

@ -40,8 +40,10 @@ func SaveName(
}
}
params.Name = name
// check if the given data works
if inv, err = makeInvoice(params, 1000); err != nil {
if inv, err = makeInvoice(params, 1000, &pin); err != nil {
return "", "", fmt.Errorf("couldn't make an invoice with the given data: %w", err)
}

View File

@ -58,6 +58,7 @@
<div class="field">
<label for="kind"> Node Backend Type </label>
<select name="kind" id="kind" id="kind" v-model="kind">
<option disabled value="">Please select one:</option>
<option value="lnd">LND</option>
<option value="sparko">Sparko</option>
<option value="lnpay">LNPay</option>
@ -136,6 +137,10 @@
isNew: true,
...initial
}
},
mounted() {
this.kind = ''
}
}

View File

@ -45,7 +45,7 @@ func handleLNURL(w http.ResponseWriter, r *http.Request) {
return
}
bolt11, err := makeInvoice(params, msat)
bolt11, err := makeInvoice(params, msat, nil)
if err != nil {
json.NewEncoder(w).Encode(
lnurl.ErrorResponse("failed to create invoice: " + err.Error()))

View File

@ -2,7 +2,7 @@ package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"strconv"
"time"
@ -22,10 +22,11 @@ func makeMetadata(params *Params) string {
return metadata
}
func makeInvoice(params *Params, msat int) (bolt11 string, err error) {
// description_hash
h := sha256.Sum256([]byte(makeMetadata(params)))
func makeInvoice(
params *Params,
msat int,
pin *string,
) (bolt11 string, err error) {
// prepare params
var backend makeinvoice.BackendParams
switch params.Kind {
@ -51,17 +52,29 @@ func makeInvoice(params *Params, msat int) (bolt11 string, err error) {
}
}
log.Debug().Int("msatoshi", msat).
Interface("backend", backend).
Str("description_hash", hex.EncodeToString(h[:])).
Msg("generating invoice")
// actually generate the invoice
return makeinvoice.MakeInvoice(makeinvoice.Params{
Msatoshi: int64(msat),
DescriptionHash: h[:],
Backend: backend,
mip := makeinvoice.Params{
Msatoshi: int64(msat),
Backend: backend,
Label: s.Domain + "/" + strconv.FormatInt(time.Now().Unix(), 16),
})
}
if pin != nil {
// use this as the description
mip.Description = fmt.Sprintf("%s's PIN for '%s@%s' lightning address: %s", s.Domain, params.Name, s.Domain, *pin)
} else {
// make the lnurlpay description_hash
h := sha256.Sum256([]byte(makeMetadata(params)))
mip.DescriptionHash = h[:]
}
// actually generate the invoice
bolt11, err = makeinvoice.MakeInvoice(mip)
log.Debug().Int("msatoshi", msat).
Interface("backend", backend).
Str("bolt11", bolt11).Err(err).
Msg("invoice generation")
return bolt11, err
}

View File

@ -8,6 +8,10 @@ body {
padding: 60px 20px 40px 20px;
}
.hidden {
display: none;
}
.title {
font-size: 40px;
font-weight: 700;