@@ -2,6 +2,7 @@ package lndclient
22
33import (
44 "context"
5+ "crypto/rand"
56 "encoding/hex"
67 "fmt"
78 "time"
@@ -12,6 +13,7 @@ import (
1213 "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
1314 "github.com/lightningnetwork/lnd/lntypes"
1415 "github.com/lightningnetwork/lnd/lnwire"
16+ "github.com/lightningnetwork/lnd/record"
1517 "github.com/lightningnetwork/lnd/routing/route"
1618 "github.com/lightningnetwork/lnd/zpay32"
1719 "google.golang.org/grpc"
@@ -88,7 +90,7 @@ type SendPaymentRequest struct {
8890
8991 // PaymentHash is the r-hash value to use within the HTLC extended to
9092 // the first hop.
91- PaymentHash [ 32 ] byte
93+ PaymentHash * lntypes. Hash
9294
9395 // FinalCLTVDelta is the CTLV expiry delta to use for the _final_ hop
9496 // in the route. This means that the final hop will have a CLTV delta
@@ -112,6 +114,9 @@ type SendPaymentRequest struct {
112114 // MaxParts is the maximum number of partial payments that may be used
113115 // to complete the full amount.
114116 MaxParts uint32
117+
118+ // KeySend is set to true if the tlv payload will include the preimage.
119+ KeySend bool
115120}
116121
117122// routerClient is a wrapper around the generated routerrpc proxy.
@@ -149,6 +154,24 @@ func (r *routerClient) SendPayment(ctx context.Context,
149154 if request .LastHopPubkey != nil {
150155 rpcReq .LastHopPubkey = request .LastHopPubkey [:]
151156 }
157+ if request .KeySend {
158+ if request .PaymentHash != nil {
159+ return nil , nil , fmt .Errorf (
160+ "keysend payment must not include a preset payment hash" )
161+ }
162+
163+ var preimage lntypes.Preimage
164+ if _ , err := rand .Read (preimage [:]); err != nil {
165+ return nil , nil , err
166+ }
167+
168+ // Override the payment hash.
169+ rpcReq .DestCustomRecords = map [uint64 ][]byte {
170+ record .KeySendType : preimage [:],
171+ }
172+ hash := preimage .Hash ()
173+ request .PaymentHash = & hash
174+ }
152175
153176 // Only if there is no payment request set, we will parse the individual
154177 // payment parameters.
0 commit comments