mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-18 04:24:28 +01:00
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:
committed by
Christian Decker
parent
a5471a405b
commit
595fbd2a19
@@ -47,6 +47,7 @@ COMMON_SRC_NOGEN := \
|
||||
common/interactivetx.c \
|
||||
common/initial_channel.c \
|
||||
common/initial_commit_tx.c \
|
||||
common/invoice_path_id.c \
|
||||
common/iso4217.c \
|
||||
common/json_filter.c \
|
||||
common/json_param.c \
|
||||
|
||||
19
common/invoice_path_id.c
Normal file
19
common/invoice_path_id.c
Normal 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);
|
||||
}
|
||||
29
common/invoice_path_id.h
Normal file
29
common/invoice_path_id.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef LIGHTNING_COMMON_INVOICE_PATH_ID_H
|
||||
#define LIGHTNING_COMMON_INVOICE_PATH_ID_H
|
||||
#include "config.h"
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
|
||||
struct secret;
|
||||
struct sha256;
|
||||
|
||||
/* String to use with makesecret to get the invoice base secret */
|
||||
#define INVOICE_PATH_BASE_STRING "bolt12-invoice-base"
|
||||
|
||||
/**
|
||||
* invoice_path_id: generate the "path_id" field for the tlv_encrypted_data_tlv
|
||||
* @ctx: tal context
|
||||
* @payment_hash: the invoice payment hash
|
||||
* @base_secret: the node-specific secret makesecret("bolt12-invoice-base")
|
||||
*
|
||||
* Receiving a blinded, encrypted tlv_encrypted_data_tlv containing
|
||||
* the correct path_id is how we know this blinded path is the correct
|
||||
* one for this invoice payment.
|
||||
*
|
||||
* It's exposed here as plugins may want to generate blinded paths.
|
||||
*/
|
||||
u8 *invoice_path_id(const tal_t *ctx,
|
||||
const struct secret *base_secret,
|
||||
const struct sha256 *payment_hash);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_INVOICE_PATH_ID_H */
|
||||
Reference in New Issue
Block a user