From 7f93577a94a80829381e67669b9744092b83714e Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Tue, 9 Jul 2024 16:18:42 +0700 Subject: [PATCH 1/2] fix: correctly pass TLVs in NIP-47 pay_keysend as per the nip-47 spec, pay_keysend TLV values are hex-encoded --- lnclient/breez/breez.go | 6 +++++- lnclient/greenlight/greenlight.go | 3 +-- lnclient/ldk/ldk.go | 6 +++++- lnclient/lnd/lnd.go | 6 +++++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lnclient/breez/breez.go b/lnclient/breez/breez.go index 82bd1dd8..7b6245bd 100644 --- a/lnclient/breez/breez.go +++ b/lnclient/breez/breez.go @@ -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, }) } diff --git a/lnclient/greenlight/greenlight.go b/lnclient/greenlight/greenlight.go index 300b7e10..5e5c98e9 100644 --- a/lnclient/greenlight/greenlight.go +++ b/lnclient/greenlight/greenlight.go @@ -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, }) } diff --git a/lnclient/ldk/ldk.go b/lnclient/ldk/ldk.go index e3a5e3b9..5f44206b 100644 --- a/lnclient/ldk/ldk.go +++ b/lnclient/ldk/ldk.go @@ -498,9 +498,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, }) } diff --git a/lnclient/lnd/lnd.go b/lnclient/lnd/lnd.go index 14da8edf..4973f96b 100644 --- a/lnclient/lnd/lnd.go +++ b/lnclient/lnd/lnd.go @@ -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 From de893d03b6fcd46a7ce0a047e1b4d443e2530f26 Mon Sep 17 00:00:00 2001 From: Adithya Vardhan Date: Wed, 10 Jul 2024 18:24:30 +0530 Subject: [PATCH 2/2] Update lnclient/greenlight/greenlight.go Co-authored-by: Roland <33993199+rolznz@users.noreply.github.com> --- lnclient/greenlight/greenlight.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnclient/greenlight/greenlight.go b/lnclient/greenlight/greenlight.go index 5e5c98e9..93f60fb7 100644 --- a/lnclient/greenlight/greenlight.go +++ b/lnclient/greenlight/greenlight.go @@ -132,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: customRecord.Value, + Value: customRecord.Value, // glalby expects hex-encoded TLV values }) }