Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
im-adithya marked this conversation as resolved.
Show resolved Hide resolved
}
const KEYSEND_CUSTOM_RECORD = 5482373484
destCustomRecords[KEYSEND_CUSTOM_RECORD] = preImageBytes
Expand Down
Loading