fix: correctly pass TLVs in NIP-47 pay_keysend (#234)

* fix: correctly pass TLVs in NIP-47 pay_keysend

as per the nip-47 spec, pay_keysend TLV values are hex-encoded

* Update lnclient/greenlight/greenlight.go

Co-authored-by: Roland <33993199+rolznz@users.noreply.github.com>

---------

Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com>
This commit is contained in:
Roland 2024-07-10 19:54:46 +07:00 committed by GitHub
parent f667675f8a
commit 947f216fd2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 5 deletions

View file

@ -119,9 +119,13 @@ func (bs *BreezService) SendPaymentSync(ctx context.Context, payReq string) (*ln
func (bs *BreezService) SendKeysend(ctx context.Context, amount uint64, destination, preimage string, custom_records []lnclient.TLVRecord) (preImage string, err error) {
extraTlvs := []breez_sdk.TlvEntry{}
for _, record := range custom_records {
decodedValue, err := hex.DecodeString(record.Value)
if err != nil {
return "", err
}
extraTlvs = append(extraTlvs, breez_sdk.TlvEntry{
FieldNumber: record.Type,
Value: []uint8(record.Value),
Value: decodedValue,
})
}

View file

@ -2,7 +2,6 @@ package greenlight
import (
"context"
"encoding/hex"
"errors"
"log"
"math/rand"
@ -133,7 +132,7 @@ func (gs *GreenlightService) SendKeysend(ctx context.Context, amount uint64, des
for _, customRecord := range custom_records {
extraTlvs = append(extraTlvs, glalby.TlvEntry{
Ty: customRecord.Type,
Value: hex.EncodeToString([]byte(customRecord.Value)),
Value: customRecord.Value, // glalby expects hex-encoded TLV values
})
}

View file

@ -526,9 +526,13 @@ func (ls *LDKService) SendKeysend(ctx context.Context, amount uint64, destinatio
customTlvs := []ldk_node.TlvEntry{}
for _, customRecord := range custom_records {
decodedValue, err := hex.DecodeString(customRecord.Value)
if err != nil {
return "", err
}
customTlvs = append(customTlvs, ldk_node.TlvEntry{
Type: customRecord.Type,
Value: []uint8(customRecord.Value),
Value: decodedValue,
})
}

View file

@ -359,7 +359,11 @@ func (svc *LNDService) SendKeysend(ctx context.Context, amount uint64, destinati
destCustomRecords := map[uint64][]byte{}
for _, record := range custom_records {
destCustomRecords[record.Type] = []byte(record.Value)
decodedValue, err := hex.DecodeString(record.Value)
if err != nil {
return "", err
}
destCustomRecords[record.Type] = decodedValue
}
const KEYSEND_CUSTOM_RECORD = 5482373484
destCustomRecords[KEYSEND_CUSTOM_RECORD] = preImageBytes