Skip to content

Commit

Permalink
fix: correctly pass TLVs in NIP-47 pay_keysend
Browse files Browse the repository at this point in the history
as per the nip-47 spec, pay_keysend TLV values are hex-encoded
  • Loading branch information
rolznz committed Jul 9, 2024
1 parent e401a1e commit 7f93577
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,
})
}

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

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 7f93577

Please sign in to comment.