Author: Yaacov Akiba Slama 2019-11-05 08:49:54
Published on: 2019-11-05T08:49:54+00:00
Rusty Russell has shared a draft of "BOLT 12", a higher-level protocol that deals with invoices over Lightning. The draft supports two simple flows: in one, a user gets an offer (`lno...`) and requests an invoice over the lightning network, obtaining one (or an error) in reply. In the other, a user gets an invoice request (`lni...`), and sends the invoice over the lightning network, retrieving an empty reply.The human-readable part of a Lightning offer is `lno`. The data part consists of three parts: 0 or more TLV encoded fields, a 32-byte nodeid, and a 64-byte signature of SHA256(hrp-as-utf8 | tlv | nodeid). Offers can request recurring payments of various kinds and specify what base currency they are calculated in. Some offers are periodic, such as a subscription service or monthly dues, and payment is expected to be repeated. A writer of an offer must use a unique `offer_identifier` for each offer, may include `recurrence` to indicate the offer should trigger time-spaced invoices, must include `amount` if it includes `recurrence`, and should gain user consent for recurring payments. A reader of an offer should gain user consent to send `delivery_` fields and warn the user if the amount of the actual invoice differs significantly from that expectation. The TLV fields in the offer include `paths`, `description`, `expiry`, `offer_identifier`, `amount`, `additional_data`, `recurrence`, `recurrance_base`, `quantity`, and `refund_for`.The Lightning Network uses various types of messages to facilitate the payment process, including offers and invoices. Each payment has a time unit, period, an optional number of payments, basetime, and paywindow. Once the node has an offer, it can request an actual invoice using the invoice_req message inside directed's onion_routing_packet, which includes a tag and other codes as required. The recipient must check offer_identifier, delivery_ fields, recurrence, and amount.There are times when it makes sense to request an invoice over another medium, such as HTTP or a QR code. The human-readable part of a Lightning invrequest is lni. The sender must use ISO 3166 alpha-2 code for delivery_country, set offer_identifier to match the offer, include key (which should use a transient unpredictable key), and set recurrence for recurring invoices. The receiver must check offer_identifier, delivery_ fields, recurrence, and amount.The merkle calculation involves adding omitted fields to omitted_fields if they were not included. Otherwise, the immediate parent merkle is created using SHA256(SHA256(tag | be64-n) | SHA256(tlv-value)), where be64-n is a 64-bit big-endian counter starting at 0 and incrementing for each leaf. Additional leaves are created until be64-n is the next power of 2, and adjacent leaves are combined using SHA256(leaf1 | leaf2) until none remain.The data part of the invoice consists of three parts: 0 or more TLV encoded fields, a 32-byte nodeid, and a 64-byte signature of SHA256(hrp-as-utf8 | tlv | nodeid). The TLV fields include invreq, paths, description, expiry, and amount. The fields paths, description, and expiry are the same as those for offers, while the optional amount field describes the amount an invoice will be accepted for. Upon parsing and accepting an invreq, the node sends an invoice_or_error_tlv within an onion, and the reply is empty.Directed messages allow peers to use existing connections to query for invoices, and they are not associated with a particular local channel. The id is a unique, transient identifier between the peers, used to identify match messages and replies. The directed and directed_reply Messages have types of 384 and consist of chain_hash, id, and onion_routing_packet or len and reply, respectively. The requirements for paths, description, and expiry are similar to update_add_htlc and update_fail_htlc, but a reasonable timeout needs to be defined after which you can forget if not replied. Rusty has also indicated that BOLT 7 gains a message/reply system encoded like htlc onions and failure messages, while BOLT 11 gains a `q` field for quantity to avoid changing the description when the user asks for an invoice for more than one of something.
Updated on: 2023-06-02T21:38:34.709511+00:00