mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
bolt12: routines to hash the invreq parts.
This gives us a unique identifier, by which we can match an invoice to their invoice_request. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
179f573e45
commit
891cef7b2b
2 changed files with 35 additions and 0 deletions
|
@ -493,6 +493,36 @@ void invoice_offer_id(const struct tlv_invoice *invoice, struct sha256 *id)
|
||||||
calc_offer(wire, id);
|
calc_offer(wire, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void calc_invreq(const u8 *tlvstream, struct sha256 *id)
|
||||||
|
{
|
||||||
|
size_t start, len;
|
||||||
|
|
||||||
|
/* BOLT-offers #12:
|
||||||
|
* - if the invoice is a response to an `invoice_request`:
|
||||||
|
* - MUST reject the invoice if all fields less than type 160
|
||||||
|
* do not exactly match the `invoice_request`.
|
||||||
|
*/
|
||||||
|
len = tlv_span(tlvstream, 0, 159, &start);
|
||||||
|
sha256(id, tlvstream + start, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void invreq_invreq_id(const struct tlv_invoice_request *invreq, struct sha256 *id)
|
||||||
|
{
|
||||||
|
u8 *wire = tal_arr(tmpctx, u8, 0);
|
||||||
|
|
||||||
|
towire_tlv_invoice_request(&wire, invreq);
|
||||||
|
calc_invreq(wire, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void invoice_invreq_id(const struct tlv_invoice *invoice, struct sha256 *id)
|
||||||
|
{
|
||||||
|
u8 *wire = tal_arr(tmpctx, u8, 0);
|
||||||
|
|
||||||
|
towire_tlv_invoice(&wire, invoice);
|
||||||
|
calc_invreq(wire, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* BOLT-offers #12:
|
/* BOLT-offers #12:
|
||||||
* ## Requirements for Invoice Requests
|
* ## Requirements for Invoice Requests
|
||||||
*
|
*
|
||||||
|
|
|
@ -143,6 +143,11 @@ void offer_offer_id(const struct tlv_offer *offer, struct sha256 *id);
|
||||||
void invreq_offer_id(const struct tlv_invoice_request *invreq, struct sha256 *id);
|
void invreq_offer_id(const struct tlv_invoice_request *invreq, struct sha256 *id);
|
||||||
void invoice_offer_id(const struct tlv_invoice *invoice, struct sha256 *id);
|
void invoice_offer_id(const struct tlv_invoice *invoice, struct sha256 *id);
|
||||||
|
|
||||||
|
/* Get invreq_id: this is used to match incoming invoices to invoice_requests
|
||||||
|
* we publish. */
|
||||||
|
void invreq_invreq_id(const struct tlv_invoice_request *invreq, struct sha256 *id);
|
||||||
|
void invoice_invreq_id(const struct tlv_invoice *invoice, struct sha256 *id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare a new invoice_request based on an offer.
|
* Prepare a new invoice_request based on an offer.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue