zpay32

package
v0.5.1-beta-rc4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2018 License: MIT Imports: 13 Imported by: 0

README

zpay32

Build Status MIT licensed GoDoc

The zpay32 package implements a basic scheme for the encoding of payment requests between two lnd nodes within the Lightning Network. The zpay32 encoding scheme uses the zbase32 scheme along with a checksum to encode a serialized payment request.

The payment request serialized by the package consist of: the destination's public key, the payment hash to use for the payment, and the value of payment to send.

Installation and Updating

$ go get -u github.com/lightningnetwork/lnd/zpay32

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Amount

func Amount(milliSat lnwire.MilliSatoshi) func(*Invoice)

Amount is a functional option that allows callers of NewInvoice to set the amount in millisatoshis that the Invoice should encode.

func CLTVExpiry

func CLTVExpiry(delta uint64) func(*Invoice)

CLTVExpiry is an optional value which allows the receiver of the payment to specify the delta between the current height and the HTLC extended to the receiver.

func Description

func Description(description string) func(*Invoice)

Description is a functional option that allows callers of NewInvoice to set the payment description of the created Invoice.

NOTE: Must be used if and only if DescriptionHash is not used.

func DescriptionHash

func DescriptionHash(descriptionHash [32]byte) func(*Invoice)

DescriptionHash is a functional option that allows callers of NewInvoice to set the payment description hash of the created Invoice.

NOTE: Must be used if and only if Description is not used.

func Destination

func Destination(destination *btcec.PublicKey) func(*Invoice)

Destination is a functional option that allows callers of NewInvoice to explicitly set the pubkey of the Invoice's destination node.

func Expiry

func Expiry(expiry time.Duration) func(*Invoice)

Expiry is a functional option that allows callers of NewInvoice to set the expiry of the created Invoice. If not set, a default expiry of 60 min will be implied.

func FallbackAddr

func FallbackAddr(fallbackAddr btcutil.Address) func(*Invoice)

FallbackAddr is a functional option that allows callers of NewInvoice to set the Invoice's fallback on-chain address that can be used for payment in case the Lightning payment fails

func RouteHint

func RouteHint(routeHint []routing.HopHint) func(*Invoice)

RouteHint is a functional option that allows callers of NewInvoice to add one or more hop hints that represent a private route to the destination.

Types

type Invoice

type Invoice struct {
	// Net specifies what network this Lightning invoice is meant for.
	Net *chaincfg.Params

	// MilliSat specifies the amount of this invoice in millisatoshi.
	// Optional.
	MilliSat *lnwire.MilliSatoshi

	// Timestamp specifies the time this invoice was created.
	// Mandatory
	Timestamp time.Time

	// PaymentHash is the payment hash to be used for a payment to this
	// invoice.
	PaymentHash *[32]byte

	// Destination is the public key of the target node. This will always
	// be set after decoding, and can optionally be set before encoding to
	// include the pubkey as an 'n' field. If this is not set before
	// encoding then the destination pubkey won't be added as an 'n' field,
	// and the pubkey will be extracted from the signature during decoding.
	Destination *btcec.PublicKey

	// Description is a short description of the purpose of this invoice.
	// Optional. Non-nil iff DescriptionHash is nil.
	Description *string

	// DescriptionHash is the SHA256 hash of a description of the purpose of
	// this invoice.
	// Optional. Non-nil iff Description is nil.
	DescriptionHash *[32]byte

	// FallbackAddr is an on-chain address that can be used for payment in
	// case the Lightning payment fails.
	// Optional.
	FallbackAddr btcutil.Address

	// RouteHints represents one or more different route hints. Each route
	// hint can be individually used to reach the destination. These usually
	// represent private routes.
	//
	// NOTE: This is optional.
	RouteHints [][]routing.HopHint
	// contains filtered or unexported fields
}

Invoice represents a decoded invoice, or to-be-encoded invoice. Some of the fields are optional, and will only be non-nil if the invoice this was parsed from contains that field. When encoding, only the non-nil fields will be added to the encoded invoice.

func Decode

func Decode(invoice string, net *chaincfg.Params) (*Invoice, error)

Decode parses the provided encoded invoice and returns a decoded Invoice if it is valid by BOLT-0011 and matches the provided active network.

func NewInvoice

func NewInvoice(net *chaincfg.Params, paymentHash [32]byte,
	timestamp time.Time, options ...func(*Invoice)) (*Invoice, error)

NewInvoice creates a new Invoice object. The last parameter is a set of variadic arguments for setting optional fields of the invoice.

NOTE: Either Description or DescriptionHash must be provided for the Invoice to be considered valid.

func (*Invoice) Encode

func (invoice *Invoice) Encode(signer MessageSigner) (string, error)

Encode takes the given MessageSigner and returns a string encoding this invoice signed by the node key of the signer.

func (*Invoice) Expiry

func (invoice *Invoice) Expiry() time.Duration

Expiry returns the expiry time for this invoice. If expiry time is not set explicitly, the default 3600 second expiry will be returned.

func (*Invoice) MinFinalCLTVExpiry

func (invoice *Invoice) MinFinalCLTVExpiry() uint64

MinFinalCLTVExpiry returns the minimum final CLTV expiry delta as specified by the creator of the invoice. This value specifies the delta between the current height and the expiry height of the HTLC extended in the last hop.

type MessageSigner

type MessageSigner struct {
	// SignCompact signs the passed hash with the node's privkey. The
	// returned signature should be 65 bytes, where the last 64 are the
	// compact signature, and the first one is a header byte. This is the
	// format returned by btcec.SignCompact.
	SignCompact func(hash []byte) ([]byte, error)
}

MessageSigner is passed to the Encode method to provide a signature corresponding to the node's pubkey.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL