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:
Rusty Russell 2022-11-09 13:02:01 +10:30 committed by Christian Decker
parent 179f573e45
commit 891cef7b2b
2 changed files with 35 additions and 0 deletions

View File

@ -493,6 +493,36 @@ void invoice_offer_id(const struct tlv_invoice *invoice, struct sha256 *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:
* ## Requirements for Invoice Requests
*

View File

@ -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 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.
*/