Skip to content

Commit

Permalink
fix: correctly pass TLVs in NIP-47 pay_keysend (#234)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Co-authored-by: Adithya Vardhan <[email protected]>
  • Loading branch information
rolznz and im-adithya authored Jul 10, 2024
1 parent f667675 commit 947f216
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lnclient/breez/breez.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
3 changes: 1 addition & 2 deletions lnclient/greenlight/greenlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package greenlight

import (
"context"
"encoding/hex"
"errors"
"log"
"math/rand"
Expand Down Expand Up @@ -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
})
}

Expand Down
6 changes: 5 additions & 1 deletion lnclient/ldk/ldk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
6 changes: 5 additions & 1 deletion lnclient/lnd/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 947f216

Please sign in to comment.