mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-17 19:12:44 +02:00
zpay: encoding and decoding of a BlindedPaymentPath
In this commit, the ability is added to encode blinded payment paths and add them to a Bolt 11 invoice.
This commit is contained in:
@@ -76,6 +76,10 @@ const (
|
||||
// probing the recipient.
|
||||
fieldTypeS = 16
|
||||
|
||||
// fieldTypeB contains blinded payment path information. This field may
|
||||
// be repeated to include multiple blinded payment paths in the invoice.
|
||||
fieldTypeB = 20
|
||||
|
||||
// maxInvoiceLength is the maximum total length an invoice can have.
|
||||
// This is chosen to be the maximum number of bytes that can fit into a
|
||||
// single QR code: https://en.wikipedia.org/wiki/QR_code#Storage
|
||||
@@ -180,9 +184,17 @@ type Invoice struct {
|
||||
// hint can be individually used to reach the destination. These usually
|
||||
// represent private routes.
|
||||
//
|
||||
// NOTE: This is optional.
|
||||
// NOTE: This is optional and should not be set at the same time as
|
||||
// BlindedPaymentPaths.
|
||||
RouteHints [][]HopHint
|
||||
|
||||
// BlindedPaymentPaths is a set of blinded payment paths that can be
|
||||
// used to find the payment receiver.
|
||||
//
|
||||
// NOTE: This is optional and should not be set at the same time as
|
||||
// RouteHints.
|
||||
BlindedPaymentPaths []*BlindedPaymentPath
|
||||
|
||||
// Features represents an optional field used to signal optional or
|
||||
// required support for features by the receiver.
|
||||
Features *lnwire.FeatureVector
|
||||
@@ -263,6 +275,15 @@ func RouteHint(routeHint []HopHint) func(*Invoice) {
|
||||
}
|
||||
}
|
||||
|
||||
// WithBlindedPaymentPath is a functional option that allows a caller of
|
||||
// NewInvoice to attach a blinded payment path to the invoice. The option can
|
||||
// be used multiple times to attach multiple paths.
|
||||
func WithBlindedPaymentPath(p *BlindedPaymentPath) func(*Invoice) {
|
||||
return func(i *Invoice) {
|
||||
i.BlindedPaymentPaths = append(i.BlindedPaymentPaths, p)
|
||||
}
|
||||
}
|
||||
|
||||
// Features is a functional option that allows callers of NewInvoice to set the
|
||||
// desired feature bits that are advertised on the invoice. If this option is
|
||||
// not used, an empty feature vector will automatically be populated.
|
||||
@@ -355,6 +376,13 @@ func validateInvoice(invoice *Invoice) error {
|
||||
return fmt.Errorf("no payment hash found")
|
||||
}
|
||||
|
||||
if len(invoice.RouteHints) != 0 &&
|
||||
len(invoice.BlindedPaymentPaths) != 0 {
|
||||
|
||||
return fmt.Errorf("cannot have both route hints and blinded " +
|
||||
"payment paths")
|
||||
}
|
||||
|
||||
// Either Description or DescriptionHash must be set, not both.
|
||||
if invoice.Description != nil && invoice.DescriptionHash != nil {
|
||||
return fmt.Errorf("both description and description hash set")
|
||||
|
Reference in New Issue
Block a user