|
| 1 | +# BOLT #13: Deputy Payment Processing |
| 2 | + |
| 3 | +Some use cases require a third party (e.g. an offline point of sale) to issue valid invoices and verify whether they have been paid. This BOLT defines how such invoices can be generated and paid using `deputy payment processing`. |
| 4 | + |
| 5 | +`deputy payment processing` relies on a deterministic preimage generation process. This allows a point of sale to generate valid invoices and validate whether they have been paid without the necessity of communicating with the recipient node at any time of the payment process. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +The point of sale supporting `deputy payment processing` |
| 10 | +* MUST issue a valid invoice corresponding to BOLT-11 |
| 11 | +* if it requires `deputy payment processing`: |
| 12 | + * MUST set the feature bit `22` in the invoice. |
| 13 | +* otherwise: |
| 14 | + * MUST set the feature bit `23` in the invoice. |
| 15 | +* MUST set a non-existing node ("deputy node") as a recipient node. |
| 16 | +* MUST add the recipient node as last routing hint. |
| 17 | +* MUST deterministically generate the preimage based on |
| 18 | + * a random nonce of 32 bytes ("preimage nonce"). |
| 19 | + * the requested amount corresponding tho the `amount` field of the invoice. |
| 20 | +* MUST ensure that no one else except the recipient node is able to reconstruct the generated preimage. |
| 21 | +* MUST expose preimage nonce as field `0` in the invoice. |
| 22 | +* MUST expose its supported offline data transmission mediums using odd feature bits according to BOLT-12. |
| 23 | +* if the generated preimage is presented through offline data transmission: |
| 24 | + * MUST grant access to the purchase. |
| 25 | +* otherwise: |
| 26 | + * MUST NOT grant access to the purchase. |
| 27 | + |
| 28 | +The sender |
| 29 | +* if the recipient requires `deputy payment processing`: |
| 30 | + * if it supports `deputy payment processing`: |
| 31 | + * MUST use `deputy payment processing`. |
| 32 | + * otherwise: |
| 33 | + * MUST NOT initiate the payment. |
| 34 | +* if the recipient optionally supprts `deputy payment processing`: |
| 35 | + * if it supports `deputy payment processing`: |
| 36 | + * MAY use `deputy payment processing`. |
| 37 | + * otherwise: |
| 38 | + * MAY use regular payment processing. |
| 39 | + |
| 40 | +If the payment shall be processed using `deputy payment processing`, the sender |
| 41 | +* if it supports none of the offline data transmission mediums supported by the receiver: |
| 42 | + * MUST NOT initiate the payment using `deputy payment processing`. |
| 43 | +* if no routing hint was specified: |
| 44 | + * MUST NOT initiate the payment using `deputy payment processing`. |
| 45 | +* if the invoice does not specify a field `0`: |
| 46 | + * MUST NOT initiate the payment using `deputy payment processing`. |
| 47 | +* otherwise: |
| 48 | + * MUST add a `dpp` onion record to the hop of the last routing hint with |
| 49 | + * `preimagenonce` set to the value of field `0` of the invoice. |
| 50 | + * `invoiceamount` set to the amount requested by the invoice in msat; `0` if the invoice does not specify a minimal amount. |
| 51 | +* if the payment was successful: |
| 52 | + * MAY present the preimage using offline data transmission and the `deputy payment preimage message`. |
| 53 | + |
| 54 | +A recipient node supporting `deputy payment processing`: |
| 55 | +* MUST set the feature bit `23` in its `init` and `node_announcement` message |
| 56 | +* if the `dpp` onion payload is set: |
| 57 | + * if the received amount is less than the `invoiceamount` specified in the `dpp` payload: |
| 58 | + * MUST fail the payment with `incorrect_or_unknown_payment_details` |
| 59 | + * if the preimage can be successfully reconstructed: |
| 60 | + * MUST claim the payment |
| 61 | + * otherwise: |
| 62 | + * MUST fail the payment with `incorrect_or_unknown_payment_details` |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +## Payload for the last Routing Hint |
| 67 | + |
| 68 | +For the recipient node to be able to reconstruct the preimage of a `dpp` payment, additional information is required. This is transmitted using the `dpp` onion payload with type number `12`. |
| 69 | + |
| 70 | +A`dpp` onion payload consists of the following parts: |
| 71 | +* [`2*byte` : `preimagenonce`]: set to the preimage nonce exposed as field `0` in the invoice |
| 72 | +* [`u64` : `invoiceamount`]: set to the amount in msat requested by the invoice |
| 73 | + |
| 74 | +## Proof of Payment |
| 75 | + |
| 76 | +In order to prove a successful payment and get access to the purchase, the `deputy payment preimage message` is used. This is an offline data transmission message (see BOLT-12) sent by the payer to the point of sale using a transmission medium supported by both parties. |
| 77 | + |
| 78 | +The message consists of the following parts: |
| 79 | +* [`2*byte`:`type`]: set to `0x0` |
| 80 | +* [`32*byte`:`preimage`]: the preimage of the payment |
| 81 | + |
| 82 | +## Deterministic preimage generation |
| 83 | + |
| 84 | +As only the point of sale and the recipient node MUST use the same preimage generation process, this process itself shall not be part of the LN specification. However, there are certain things to consider when implementing such a process: |
| 85 | + |
| 86 | +* The minimal requested amount SHOULD be used as input parameter for the preimage generation. Thereby it is ensured that the recipient node will generate a wrong preimage and therefore fail the payment when a fraudulent sender specifies a different amount in the `invoiceamount` part of the `dpp` onion payload. |
| 87 | +* The preimage generation process SHOULD ensure that two invoices with the same amount do not have the same preimage. The random generated preimage nonce (field `0` in the invoices / `preimagenonce` part of the `dpp` onion payload) MAY be used for this. |
| 88 | +* Only the point of sale and the recipient node SHOULD be able to generate the same preimage. In order to achieve this, some sort of shared secret MAY be used as an input parameter for the preimage generation. |
| 89 | + |
| 90 | + |
| 91 | +### Example |
| 92 | +The following preimage formula meets all of the above requirements: |
| 93 | + |
| 94 | +`preimage = sha256( concat( s, n, a))` |
| 95 | + |
| 96 | +Whereas the parameters are defined as follows: |
| 97 | +* `s`: shared secret only known by the point of sale and the recipient node |
| 98 | +* `n`: preimage nonce (field `0` in the invoices / `preimagenonce` part of the `dpp` onion payload) |
| 99 | +* `a`: minimal requested amount in msat (`amount` in the invoices / `invoiceamount` part of the `dpp` onion record) |
| 100 | + |
| 101 | +`sha256` is used to always get a preimage of `32 * byte` length. |
| 102 | + |
| 103 | +#### Point of Sale: Invoice generation example in JavaScript |
| 104 | +```javascript |
| 105 | +const sharedSecret = toUtf8Bytes('Sup3rS3cur3!'); |
| 106 | +const preimageNonce = crypto.randomBytes(32); |
| 107 | +const amountMsat = 1000; |
| 108 | + |
| 109 | +const preimage = sha256.create(); |
| 110 | +preimage.update( |
| 111 | + sharedSecret |
| 112 | + .concat(Array.from(preimageNonce)) |
| 113 | + .concat(this.amountInMiliSatoshisBytes) |
| 114 | +); |
| 115 | +``` |
| 116 | + |
| 117 | +#### recipient Node: Preimage reconstruction example in Go |
| 118 | +```go |
| 119 | +secret := []byte("Sup3rS3cur3!") |
| 120 | +var amount = make([]byte, 8) |
| 121 | +binary.BigEndian.PutUint64( |
| 122 | + amount, |
| 123 | + payload.DeputyPaymentProcessing().InvoiceAmount(), |
| 124 | +) |
| 125 | +nonce := payload.DeputyPaymentProcessing().PreimageNonce() |
| 126 | + |
| 127 | +preimageBase := secret |
| 128 | +preimageBase = append(preimageBase, nonce[:]...) |
| 129 | +preimageBase = append(preimageBase, amount...) |
| 130 | + |
| 131 | +preimageInput := sha256.Sum256(preimageBase) |
| 132 | +preimage, err := lntypes.MakePreimage(preimageInput[:]) |
| 133 | +``` |
| 134 | + |
| 135 | + |
| 136 | +## Example Invoices |
| 137 | +TODO |
0 commit comments