createinvoice: make a minimal blinded "path" in bolt12 invoice if none presented.

The "path" is just a message to ourselves.  This meets the minimal
requirement for bolt12 invoices: that there be a blinded path (at
least so we can use the path_id inside in place of "payment_secret").

We expose the method to make this path_id to a common routine: offers
will need this for generating more sophisticated paths.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-11-09 12:57:04 +10:30
committed by Christian Decker
parent a5471a405b
commit 595fbd2a19
9 changed files with 155 additions and 1 deletions

19
common/invoice_path_id.c Normal file
View File

@@ -0,0 +1,19 @@
#include "config.h"
#include <bitcoin/privkey.h>
#include <ccan/crypto/sha256/sha256.h>
#include <common/invoice_path_id.h>
u8 *invoice_path_id(const tal_t *ctx,
const struct secret *base_secret,
const struct sha256 *payment_hash)
{
struct sha256_ctx shactx;
struct sha256 secret;
sha256_init(&shactx);
sha256_update(&shactx, base_secret, sizeof(*base_secret));
sha256_update(&shactx, payment_hash, sizeof(*payment_hash));
sha256_done(&shactx, &secret);
return (u8 *)tal_dup(ctx, struct sha256, &secret);
}