feat: add pubkey hex check

This commit is contained in:
Adithya Vardhan
2023-02-22 18:10:23 +05:30
parent c7d2f3d559
commit 12a6fe1adc
3 changed files with 14 additions and 0 deletions

View File

@@ -1,10 +1,12 @@
package controllers
import (
"encoding/hex"
"fmt"
"net/http"
"strconv"
"github.com/getAlby/lndhub.go/common"
"github.com/getAlby/lndhub.go/lib"
"github.com/getAlby/lndhub.go/lib/responses"
"github.com/getAlby/lndhub.go/lib/service"
@@ -91,6 +93,10 @@ func (controller *KeySendController) KeySend(c echo.Context) error {
if err != nil {
return err
}
if _, err := hex.DecodeString(invoice.DestinationPubkeyHex); err != nil || len(invoice.DestinationPubkeyHex) != common.DestinationPubkeyHexSize {
c.Logger().Errorf("Invalid destination pubkey hex user_id:%v pubkey:%v", userID, len(invoice.DestinationPubkeyHex))
return c.JSON(http.StatusBadRequest, responses.BadArgumentsError)
}
invoice.DestinationCustomRecords = map[uint64][]byte{}
for key, value := range reqBody.CustomRecords {
intKey, err := strconv.Atoi(key)