BOLT 11: Invoice Protocol for Lightning Payments
A simple, extendable, QR-code-ready protocol for requesting payments over Lightning.
No reviewsSpecification
BOLT #11: Invoice Protocol for Lightning Payments
A simple, extendable, QR-code-ready protocol for requesting payments over Lightning.
Table of Contents
- Encoding Overview
- Human-Readable Part
- Data Part
- Payer / Payee Interactions
- Implementation
- Examples
- Authors
Encoding Overview
The format for a Lightning invoice uses bech32 encoding, which is already used for Bitcoin Segregated Witness. It can be simply reused for Lightning invoices even though its 6-character checksum is optimized for manual entry, which is unlikely to happen often given the length of Lightning invoices.
If a URI scheme is desired, the current recommendation is to either use 'lightning:' as a prefix before the BOLT-11 encoding (note: not 'lightning://'), or for fallback to Bitcoin payments, to use 'bitcoin:', as per BIP-21, with the key 'lightning' and the value equal to the BOLT-11 encoding.
Requirements
A writer:
- MUST encode the payment request in Bech32 (see BIP-0173)
- SHOULD use upper case for QR codes (see BIP-0173)
- MAY exceed the 90-character limit specified in BIP-0173.
A reader:
- MUST parse the address as Bech32, as specified in BIP-0173 (also without the character limit).
- Note: this includes handling uppercase as specified by BIP-0173
- if the checksum is incorrect:
- MUST fail the payment.
Human-Readable Part
The human-readable part of a Lightning invoice consists of two sections:
prefix:ln+ BIP-0173 currency prefix (e.g.lnbcfor Bitcoin mainnet,lntbfor Bitcoin testnet,lntbsfor Bitcoin signet, andlnbcrtfor Bitcoin regtest)amount: optional number in that currency, followed by an optionalmultiplierletter. The unit encoded here is the 'social' convention of a payment unit -- in the case of Bitcoin the unit is 'bitcoin' NOT satoshis.
The following multiplier letters are defined:
m(milli): multiply by 0.001u(micro): multiply by 0.000001n(nano): multiply by 0.000000001p(pico): multiply by 0.000000000001
Requirements
A writer:
- MUST encode
prefixusing the currency required for successful payment. - if a specific minimum
amountis required for successful payment:- MUST include that
amount. - MUST encode
amountas a positive decimal integer with no leading 0s. - If the
pmultiplier is used the last decimal ofamountMUST be0. - SHOULD use the shortest representation possible, by using the largest multiplier or omitting the multiplier.
- MUST include that
A reader:
- if it does NOT understand the
prefix:- MUST fail the payment.
- if the
amountis empty:- SHOULD indicate to the payer that amount is unspecified.
- otherwise:
- if
amountcontains a non-digit OR is followed by anything except amultiplier(see table above):- MUST fail the payment.
- if the
multiplieris present:- MUST multiply
amountby themultipliervalue to derive the amount required for payment. - if multiplier is
pand the last decimal ofamountis not 0:- MUST fail the payment.
- MUST multiply
- if
Rationale
The amount is encoded into the human readable part, as it's fairly
readable and a useful indicator of how much is being requested.
Donation addresses often don't have an associated amount, so amount
is optional in that case. Usually a minimum payment is required for
whatever is being offered in return.
The p multiplier would allow to specify sub-millisatoshi amounts, which cannot be transferred on the network, since HTLCs are denominated in millisatoshis.
Requiring a trailing 0 decimal ensures that the amount represents an integer number of millisatoshis.
Note that non-largest multipliers have been encountered in the wild, and as such invoice parsers should handle them.
Data Part
The data part of a Lightning invoice consists of multiple sections:
timestamp: seconds-since-1970 (35 bits, big-endian)- zero or more tagged parts
signature: compact ECDSA/secp256k1 signature of the above (520 bits: 64-byte R||S + 1-byte recovery id)
Requirements
A writer:
- MUST set
timestampto the number of seconds since Midnight 1 January 1970, UTC in big-endian. - MUST set
signatureto a valid compact ECDSA signature over secp256k1 of the SHA-256 hash of: the human-readable part (as UTF-8 bytes) concatenated with the data part (excluding the signature), with 0 bits appended to pad to a byte boundary. The signature is encoded as 64 bytes (R || S), followed by a trailing 1-byte recovery id in {0,1,2,3}.
A reader:
- MUST check that the
signatureis valid (see thentagged field specified below).
Rationale
signature covers an exact number of bytes even though the SHA2
standard actually supports hashing in bit boundaries, because it's not widely
implemented. The recovery ID allows public-key recovery, so the
identity of the payee node can be implied.
Tagged Fields
Each Tagged Field is of the form:
type(5 bits)data_length(10 bits, big-endian)data(data_lengthx 5 bits)
Note that the maximum length of a Tagged Field's data is constricted by the maximum value of data_length. This is 1023 x 5 bits, or 639 bytes.
Currently defined tagged fields are:
p(1):data_length52. 256-bit SHA256 payment_hash. Preimage of this provides proof of payment.s(16):data_length52. This 256-bit secret prevents forwarding nodes from probing the payment recipient.d(13):data_lengthvariable. Short description of purpose of payment (UTF-8), e.g. '1 cup of coffee' or 'ナンセンス 1杯'm(27):data_lengthvariable. Additional metadata to attach to the payment. Note that the size of this field is limited by the maximum hop payload size. Long metadata fields reduce the maximum route length.n(19):data_length53. 33-byte public key of the payee nodeh(23):data_length52. 256-bit description of purpose of payment (SHA256). This is used to commit to an associated description that is over 639 bytes, but the transport mechanism for the description in that case is transport specific and not defined here.x(6):data_lengthvariable.expirytime in seconds (big-endian). Default is 3600 (1 hour) if not specified.c(24):data_lengthvariable.min_final_cltv_expiry_deltato use for the last HTLC in the route. Default is 18 if not specified.f(9):data_lengthvariable, depending on version. Fallback on-chain address: for Bitcoin, this starts with a 5-bitversionand contains a witness program or P2PKH or P2SH address.r(3):data_lengthvariable. One or more entries containing extra routing information for a private route; there may be more than onerfieldpubkey(264 bits)short_channel_id(64 bits)fee_base_msat(32 bits, big-endian)fee_proportional_millionths(32 bits, big-endian)cltv_expiry_delta(16 bits, big-endian)
9(5):data_lengthvariable. One or more 5-bit values containing features supported or required for receiving this payment. See Feature Bits.
Requirements
A writer:
- MUST include exactly one
pfield. - MUST include exactly one
sfield. - MUST set
payment_hashto the SHA2 256-bit hash of thepayment_preimagethat will be given in return for payment. - MUST include either exactly one
dor exactly onehfield.- if
dis included:- MUST set
dto a valid UTF-8 string. - SHOULD use a complete description of the purpose of the payment.
- MUST set
- if
his included:- MUST make the preimage of the hashed description in
havailable through some unspecified means.- SHOULD use a complete description of the purpose of the payment.
- MUST make the preimage of the hashed description in
- if
- MAY include one
xfield.- if
xis included:- MUST use the minimum
data_lengthpossible, i.e. no leading 0 field-elements.
- MUST use the minimum
- if
- SHOULD include one
cfield (min_final_cltv_expiry_delta).- MUST set
cto the minimumcltv_expiryit will accept for the last HTLC in the route. - MUST use the minimum
data_lengthpossible, i.e. no leading 0 field-elements.
- MUST set
- MAY include one
nfield. (Otherwise performing public-key recovery is required)- MUST set
nto the public key used to create thesignature.
- MUST set
- MAY include one or more
ffields.- for Bitcoin payments:
- MUST set an
ffield to a valid witness version and program, OR to17followed by a public key hash, OR to18followed by a script hash.
- MUST set an
- for Bitcoin payments:
- if there is NOT a public channel associated with its public key:
- MUST include at least one
rfield.rfield MUST contain one or more ordered entries, indicating the forward route from a public node to the final destination.- Note: for each entry, the
pubkeyis the node ID of the start of the channel;short_channel_idis the short channel ID field to identify the channel; andfee_base_msat,fee_proportional_millionths, andcltv_expiry_deltaare as specified in BOLT #7.
- Note: for each entry, the
- MAY include more than one
rfield to provide multiple routing options.
- MUST include at least one
- if
9contains non-zero bits:- MUST use the minimum
data_lengthpossible to encode the non-zero bits with no 0 field-elements at the start.
- MUST use the minimum
- otherwise:
- MUST omit the
9field altogether.
- MUST omit the
- MUST pad field data to a multiple of 5 bits, using 0s.
- if a writer offers more than one of any field type, it:
- MUST specify the most-preferred field first, followed by less-preferred fields, in order.
A reader:
- MUST skip over
ffields that use an unknownversion. - MUST fail the payment if any field with fixed
data_length(p,h,s,n) does not have the correct length (52, 52, 52, 53). - MUST fail the payment if neither a
dfield nor ahfield is present, or if both are present. - if the
9field contains unknown odd bits that are non-zero:- MUST ignore the bit.
- if the
9field contains unknown even bits that are non-zero:- MUST fail the payment.
- SHOULD indicate the unknown bit to the user.
- MUST check that the SHA2 256-bit hash in the
hfield exactly matches the hashed description. - if a valid
nfield is provided:- MUST use the
nfield to validate the signature instead of performing public-key recovery. - If the signature is not compliant with the low-S standard rule<sup>low-S</sup>:
- MUST fail the payment
- MUST use the
- otherwise:
- MUST perform ECDSA public-key recovery and accept both high-S and low-S signatures.
- if a valid
sfield is not provided:- MUST fail the payment.
- otherwise:
- MUST use the
sfield aspayment_secret
- MUST use the
- if the
cfield (min_final_cltv_expiry_delta) is not provided:- MUST use an expiry delta of at least 18 when making the payment
- if an
mfield is provided:- MUST use that as
payment_metadata
- MUST use that as
- if a
c,x, or9field is provided which has a non-minimaldata_length(i.e. begins with 0 field elements):- SHOULD treat the invoice as invalid.
Rationale
The type-and-length format allows future extensions to be backward
compatible. data_length is always a multiple of 5 bits, for easy
encoding and decoding.
The d field allows inline descriptions, but may be insufficient for
complex orders. Thus, the h field allows a summary: though the method
by which the description is served is as-yet unspecified and will
probably be transport dependent.
The m field allows metadata to be attached to the payment. This supports
applications where the recipient doesn't keep any context for the payment.
The n field can be used to explicitly specify the destination node ID,
instead of requiring public-key recovery.
The x field gives warning as to when a payment will be
refused: mainly to avoid confusion. The default was chosen
to be reasonable for most payments and to allow sufficient time for
on-chain payment, if necessary.
The c field allows a way for the destination node to require a specific
minimum CLTV expiry for its incoming HTLC. Destination nodes may use this
to require a higher, more conservative value than the default one (depending
on their fee estimation policy and their sensitivity to time locks). Note
that remote nodes in the route specify their required cltv_expiry_delta
in the channel_update message, which they can update at all times.
The f field allows on-chain fallback; however, this may not make sense for
tiny or time-sensitive payments. It's possible that new
address forms will appear; thus, multiple f fields (in an implied
preferred order) help with transition, and f fields with versions 19-31
will be ignored by readers.
The r field allows limited routing assistance: as specified, it only
allows minimum information to use private channels, however, it could also
assist in future partial-knowledge routing.
Security Considerations for Payment Descriptions
Payment descriptions are user-defined and provide a potential avenue for injection attacks: during the processes of both rendering and persistence.
Payment descriptions should always be sanitized before being displayed in HTML/Javascript contexts (or any other dynamically interpreted rendering frameworks). Implementers should be extra perceptive to the possibility of reflected XSS attacks, when decoding and displaying payment descriptions. Avoid optimistically rendering the contents of the payment request until all validation, verification, and sanitization processes have been successfully completed.
Furthermore, consider using prepared statements, input validation, and/or escaping, to protect against injection vulnerabilities in persistence engines that support SQL or other dynamically interpreted querying languages.
Don't be like the school of Little Bobby Tables.
Feature Bits
Feature bits allow forward and backward compatibility, and follow the
it's ok to be odd rule. Features appropriate for use in the 9 field
are marked in BOLT 9.
The field is
[Content truncated — view full spec at source]
Discussion (0 threads)
No discussion yet. Be the first to comment.