Documentation ¶
Index ¶
- Constants
- Variables
- func CalculateRoot(branches []*TLVBranch) chainhash.Hash
- func EncodeBlindedRouteData(data *BlindedRouteData) ([]byte, error)
- func EncodeInvoice(i *Invoice) ([]byte, error)
- func EncodeInvoiceRequest(i *InvoiceRequest) ([]byte, error)
- func EncodeOffer(offer *Offer) ([]byte, error)
- func EncodeOnionMessagePayload(o *OnionMessagePayload) ([]byte, error)
- func MerkleRoot(records []tlv.Record) (lntypes.Hash, error)
- func ValidateFinalPayload(tlvType tlv.Type) error
- type BlindedHop
- type BlindedRouteData
- type FinalHopPayload
- type Invoice
- type InvoiceRequest
- type Offer
- type OnionMessage
- type OnionMessagePayload
- type ReplyPath
- type TLVBranch
- type TLVLeaf
Constants ¶
const ( // InvoiceRequestNamespaceType is a record containing the sub-namespace // of tlvs that request invoices for offers. InvoiceRequestNamespaceType tlv.Type = 64 // InvoiceNamespaceType is a record containing the sub-namespace of // tlvs that describe an invoice. InvoiceNamespaceType tlv.Type = 66 )
const OnionMessageType = 513
OnionMessageType is the protocol message type used for onion messages in lnd.
Variables ¶
var ( // ErrNoCreationTime is returned when an invoice does not have a // created at tlv. ErrNoCreationTime = errors.New("invoice requires creation time") // ErrNoPaymentHash is returned when an invoice does not have a // payment hash tlv. ErrNoPaymentHash = errors.New("invoice requires payment hash") // ErrNoAmount is returned when an invoice doesn't have an amount tlv. ErrNoAmount = errors.New("invoice requires amount") )
var ( // ErrOfferIDRequired is returned when an invoice request does not // contain an associated offer id. ErrOfferIDRequired = errors.New("offer id required") // ErrPayerKeyRequired is returned when an invoice request does not // contain a payer key. ErrPayerKeyRequired = errors.New("payer key required") // ErrSignatureRequired is returned when an invoice request does not // contain a signature. ErrSignatureRequired = errors.New("signature required") // ErrBelowMinAmount is returned if an attempt to make a request for // less than the offer minimum is created. ErrBelowMinAmount = errors.New("amount less than offer minimum") // ErrOutsideQuantityRange is returned if a quantity outside of the // offer's range is requested. ErrOutsideQuantityRange = errors.New("quantity outside range") // ErrNoQuantity is returned when an invoice request for a specific // quantity is requested from an offer with no quantity tlvs specified. ErrNoQuantity = errors.New("quantity requested for offer with no " + "quantity") // ErrQuantityRequired is returned when an invoice request does not // specify quantity for an offer that provides a quantity range. ErrQuantityRequired = errors.New("quantity set in offer but not " + "request") )
var ( // TLVTag is the tag used for nodes containing TLV values. TLVTag = []byte("LnLeaf") // NonceTag is the tag used for nodes containing TLV nonces. NonceTag = []byte("LnAll") // BranchTag is the tag for intermediate branches. BranchTag = []byte("LnBranch") // ErrOddLeafNodes is returned if an attempt to create our first // level of branches is made with an odd number of leaves. Since each // TLV is matched with a nonce leaf in this construction, there should // always be an even number of leaves. ErrOddLeafNodes = errors.New("even number of leaf nodes expected") // ErrNoTLVs is returned if an attempt to calculate a merkle tree with // no non-signature tlv records is made. ErrNoTLVs = errors.New("at least 1 non-signature TLV required") )
var ( // ErrNodeIDRequired is returned when a node pubkey is not provided // for an offer. Note that when blinded paths are supported, we can // relax this requirement. ErrNodeIDRequired = errors.New("node pubkey required for offer") // ErrQuantityRange is returned when we get an min/max quantity range // with min > max, which does not make sense. ErrQuantityRange = errors.New("invalid quantity range") // ErrDescriptionRequried is returned when an offer is invalid because // does not contain a description. ErrDescriptionRequried = errors.New("offer description required") )
var ( // ErrNotFinalPayload is returned when a final hop payload is not // within the correct range. ErrNotFinalPayload = errors.New("final hop payloads type should be " + ">= 64") // ErrNoHops is returned when we handle a reply path that does not // have any hops (this makes no sense). ErrNoHops = errors.New("reply path requires hops") )
var ( // ErrInvalidSig is returned when the signature tlv value is // invalid. ErrInvalidSig = errors.New("invalid signature") )
Functions ¶
func CalculateRoot ¶
CalculateRoot combines a set of branches into a merkle root.
func EncodeBlindedRouteData ¶
func EncodeBlindedRouteData(data *BlindedRouteData) ([]byte, error)
EncodeBlindedRouteData encodes a blinded route tlv stream.
func EncodeInvoice ¶
EncodeInvoice encodes a bolt12 invoice as a tlv stream.
func EncodeInvoiceRequest ¶
func EncodeInvoiceRequest(i *InvoiceRequest) ([]byte, error)
EncodeInvoiceRequest encodes a bolt12 invoice request as a tlv stream.
func EncodeOnionMessagePayload ¶
func EncodeOnionMessagePayload(o *OnionMessagePayload) ([]byte, error)
EncodeOnionMessagePayload encodes an onion message's final payload.
func MerkleRoot ¶
MerkleRoot computes a merkle tree for the set of offer tlv records provided.
func ValidateFinalPayload ¶
ValidateFinalPayload returns an error if a tlv is not within the range reserved for final papyloads.
Types ¶
type BlindedHop ¶
type BlindedHop struct { // BlindedNodeID is the blinded node id of a node in the path. BlindedNodeID *btcec.PublicKey // EncryptedData is the encrypted data to be included for the node. EncryptedData []byte }
BlindedHop contains a blinded node ID and encrypted data used to send onion messages over blinded routes.
type BlindedRouteData ¶
type BlindedRouteData struct { // NextNodeID is the unblinded node id of the next hop in the route. NextNodeID *btcec.PublicKey // NextBlindingOverride is an optional blinding override used to switch // out ephemeral keys. NextBlindingOverride *btcec.PublicKey }
BlindedRouteData holds the fields that we encrypt in route blinding blobs.
func DecodeBlindedRouteData ¶
func DecodeBlindedRouteData(data []byte) (*BlindedRouteData, error)
DecodeBlindedRouteData decodes a blinded route tlv stream.
type FinalHopPayload ¶
type FinalHopPayload struct { // TLVType is the type for the payload. TLVType tlv.Type // Value is the raw byte value read for this tlv type. This field is // expected to contain "sub-tlv" namespaces, and will require further // decoding to be used. Value []byte }
FinalHopPayload contains values reserved for the final hop, which are just directly read from the tlv stream.
func (*FinalHopPayload) Validate ¶
func (f *FinalHopPayload) Validate() error
Validate performs validation of items added to the final hop's payload in an onion. This function does not validate payload length to allow "marker-tlvs" that have no body.
type Invoice ¶
type Invoice struct { // Chainhash is the hash of the genesis block of the chain that the // invoice is for. Chainhash lntypes.Hash // OfferID is the merkle root of the offer this invoice is associated // with. OfferID lntypes.Hash // Amount is the amount that the invoice is for. Amount lndwire.MilliSatoshi // Description is an optional description of the invoice. Description string // Features is the set of features the invoice requires. Features *lndwire.FeatureVector // NodeID is the node ID for the recipient. NodeID *btcec.PublicKey // Quantity is an optional quantity of items for the invoice. Quantity uint64 // PayerKey is the paying party's "proof of payee" key. PayerKey *btcec.PublicKey // PayerNote is an optional note from the paying party. PayerNote string // CreatedAt is the time the invoice was created. CreatedAt time.Time // PaymentHash is the payment hash for this invoice. PaymentHash lntypes.Hash // RelativeExpiry is the relative expiry in seconds from the invoice's // created time. RelativeExpiry time.Duration // CLTVExpiry is the minimum final cltv expiry for the invoice. CLTVExpiry uint64 // PayerInfo is an arbitrary piece of data set by the payer. PayerInfo []byte // Signature is a signature over the tlv merkle root of the invoice's // fields. Signature *[64]byte // MerkleRoot is the merkle root of all the non-signature tlvs included // in the invoice. This field isn't actually encoded in our tlv stream, // but rather calculated from it. MerkleRoot lntypes.Hash }
Invoice represents a bolt 12 invoice.
func DecodeInvoice ¶
DecodeInvoice decodes a bolt12 invoice tlv stream.
type InvoiceRequest ¶
type InvoiceRequest struct { // Chainhash is the hash of the genesis block of the chain that the // invoice request is for. Chainhash lntypes.Hash // OfferID is the merkle root of the offer this request is associated // with. OfferID lntypes.Hash // Amount is the invoice amount that the request is for. Amount lndwire.MilliSatoshi // Features is the set of features required for the invoice. Features *lndwire.FeatureVector // Quantity is the number of items that the invoice is for. Quantity uint64 // PayerKey is a proof-of-payee key for the sender. PayerKey *btcec.PublicKey // PayerNote is a note from the sender. PayerNote string // PayerInfo is arbitrary information included by the sender. PayerInfo []byte // Signature is an optional signature on the tlv merkle root of the // request. Signature *[64]byte // MerkleRoot is the merkle root of all the non-signature tlvs included // in the invoice request. This field isn't actually encoded in our // tlv stream, but rather calculated from it. MerkleRoot lntypes.Hash }
InvoiceRequest represents a bolt 12 request for an invoice.
func DecodeInvoiceRequest ¶
func DecodeInvoiceRequest(b []byte) (*InvoiceRequest, error)
DecodeInvoiceRequest decodes a bolt12 invoice request tlv stream.
func NewInvoiceRequest ¶
func NewInvoiceRequest(offer *Offer, amount lnwire.MilliSatoshi, quantity uint64, payerKey *btcec.PublicKey, payerNote string) ( *InvoiceRequest, error)
NewInvoiceRequest returns a new invoice request for the offer provided. This function does not produce a signature for the invoice, but it does calculate its tlv merkle root.
func (*InvoiceRequest) SignatureDigest ¶
func (i *InvoiceRequest) SignatureDigest() chainhash.Hash
SignatureDigest returns the tagged digest that is signed for invoice requests.
func (*InvoiceRequest) Validate ¶
func (i *InvoiceRequest) Validate() error
Validate performs validation on an invoice request as described in the specification.
type Offer ¶
type Offer struct { // Chainhash is the genesis block hash of the network that the offer is // for. Chainhash lntypes.Hash // MinimumAmount is an optional minimum amount for the offer. MinimumAmount lnwire.MilliSatoshi // Description is an optional description of the offer. Description string // Features are the specification features that the offer requires and // supports. Features *lnwire.FeatureVector // Expiry is an optional expiry time of the offer. Expiry time.Time // Issuer identifies the issuing party. Issuer string // QuantityMin is the minimum number of invoices for an offer. QuantityMin uint64 // QuantityMax is the maximum number of invoices for an offer. QuantityMax uint64 // NodeID is the public key advertized by the offering node. // Note: at present this is encoded as a x-only 32 byte pubkey, but the // spec is set to change, so in future this should be encoded as a 33 // byte compressed pubkey. NodeID *btcec.PublicKey // Signature is the bip340 signature for the offer. Signature *[64]byte // MerkleRoot is the merkle root of all the non-signature tlvs included // in the offer. This field isn't actually encoded in our tlv stream, // but rather calculated from it. MerkleRoot lntypes.Hash }
Offer represents a bolt 12 offer.
func DecodeOffer ¶
DecodeOffer decodes a bolt 12 offer TLV stream.
type OnionMessage ¶
type OnionMessage struct { // BlindingPoint is the route blinding ephemeral pubkey to be used for // the onion message. BlindingPoint *btcec.PublicKey // OnionBlob is the raw serialized mix header used to relay messages in // a privacy-preserving manner. This blob should be handled in the same // manner as onions used to route HTLCs, with the exception that it uses // blinded routes by default. OnionBlob []byte }
OnionMessage represents an onion message used to communicate with peers.
func NewOnionMessage ¶
func NewOnionMessage(blindingPoint *btcec.PublicKey, onion []byte) *OnionMessage
NewOnionMessage creates a new onion message.
func (*OnionMessage) Decode ¶
func (o *OnionMessage) Decode(r io.Reader, _ uint32) error
Decode reads the bytes stream and converts it to the object.
This is part of the lnwire.Message interface in lnd.
func (*OnionMessage) Encode ¶
func (o *OnionMessage) Encode(w *bytes.Buffer, _ uint32) error
Encode converts object to the bytes stream and write it into the write buffer.
This is part of the lnwire.Message interface in lnd.
func (*OnionMessage) MsgType ¶
func (o *OnionMessage) MsgType() lndwire.MessageType
MsgType returns the integer uniquely identifying this message type on the wire.
This is part of the lnwire.Message interface in lnd.
type OnionMessagePayload ¶
type OnionMessagePayload struct { // ReplyPath contains a blinded path that can be used to respond to an // onion message. ReplyPath *ReplyPath // EncryptedData contains enrypted data for the recipient. EncryptedData []byte // FinalHopPayloads contains any tlvs with type > 64 that FinalHopPayloads []*FinalHopPayload }
OnionMessagePayload contains the contents of an onion message payload.
func DecodeOnionMessagePayload ¶
func DecodeOnionMessagePayload(o []byte) (*OnionMessagePayload, error)
DecodeOnionMessagePayload decodes an onion message's payload.
type ReplyPath ¶
type ReplyPath struct { // FirstNodeID is the pubkey of the first node in the reply path. FirstNodeID *btcec.PublicKey // BlindingPoint is the ephemeral pubkey used in route blinding. BlindingPoint *btcec.PublicKey // Hops is a set of blinded hops in the route, starting with the blinded // introduction node (first node id). Hops []*BlindedHop }
ReplyPath is a blinded path used to respond to onion messages.
type TLVBranch ¶
type TLVBranch struct {
// contains filtered or unexported fields
}
TLVBranch represents inner branch nodes in a tlv merkle tree.
func CreateTLVBranches ¶
CreateTLVBranches creates a set of branches from an initial set of leaves.
func (*TLVBranch) TaggedHash ¶
TaggedHash produces a tagged hash for the branch, as defined by: H(tag, msg) = sha256(sha256(tag) || sha256(tag) || msg) TaggedHash = H("LnBranch" , left || right)
Note that this function assumes that left <= right
type TLVLeaf ¶
type TLVLeaf struct { // Tag is the tag to be used when hashing the value into a node. Tag []byte // Value is the value contained in the leaf. Value []byte }
TLVLeaf represents a leaf in our offer merkle tree.
func CreateTLVLeaves ¶
CreateTLVLeaves creates a set of merkle leaves for a set of offer TLV records, excluding signature fields. A tlvEncode function is passed in for easy testing.
func (*TLVLeaf) TaggedHash ¶
TaggedHash computes the tagged hash of a leaf, as defined by: H(tag, msg) = sha256(sha256(tag) || sha256(tag) || msg) TaggedHash = H("LnLeaf"/"LnAll" + all_tlvs , tlv )
Note: the String() function on chainhash.Hash produces a hex-encoded byte reversed hash (and the spec test vectors aren't reversed).