2022-10-17 02:44:39 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <common/blindedpay.h>
|
|
|
|
#include <common/bolt12.h>
|
2022-11-09 02:30:10 +01:00
|
|
|
#include <common/onion_encode.h>
|
2022-10-17 02:44:39 +02:00
|
|
|
|
|
|
|
u8 **blinded_onion_hops(const tal_t *ctx,
|
|
|
|
struct amount_msat final_amount,
|
|
|
|
u32 final_cltv,
|
2023-01-12 04:53:38 +01:00
|
|
|
struct amount_msat total_amount,
|
2022-10-17 02:44:39 +02:00
|
|
|
const struct blinded_path *path)
|
|
|
|
{
|
|
|
|
u8 **onions = tal_arr(ctx, u8 *, tal_count(path->path));
|
|
|
|
|
|
|
|
assert(tal_count(onions) > 0);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < tal_count(onions); i++) {
|
|
|
|
bool first = (i == 0);
|
|
|
|
bool final = (i == tal_count(onions) - 1);
|
|
|
|
|
2024-03-18 04:01:06 +01:00
|
|
|
/* BOLT #4:
|
2022-10-17 02:44:39 +02:00
|
|
|
* - For every node inside a blinded route:
|
2022-11-09 02:30:10 +01:00
|
|
|
* - MUST include the `encrypted_recipient_data` provided by the
|
2022-10-17 02:44:39 +02:00
|
|
|
* recipient
|
|
|
|
* - For the first node in the blinded route:
|
|
|
|
* - MUST include the `blinding_point` provided by the
|
2022-11-09 02:30:10 +01:00
|
|
|
* recipient in `current_blinding_point`
|
2022-10-17 02:44:39 +02:00
|
|
|
* - If it is the final node:
|
2023-01-12 04:53:38 +01:00
|
|
|
* - MUST include `amt_to_forward`, `outgoing_cltv_value` and `total_amount_msat`.
|
2024-03-18 04:01:06 +01:00
|
|
|
*...
|
2022-11-09 02:30:10 +01:00
|
|
|
* - MUST NOT include any other tlv field.
|
2022-10-17 02:44:39 +02:00
|
|
|
*/
|
|
|
|
onions[i] = onion_blinded_hop(onions,
|
|
|
|
final ? &final_amount : NULL,
|
2023-01-12 04:53:38 +01:00
|
|
|
final ? &total_amount : NULL,
|
2022-10-17 02:44:39 +02:00
|
|
|
final ? &final_cltv : NULL,
|
|
|
|
path->path[i]->encrypted_recipient_data,
|
|
|
|
first ? &path->blinding : NULL);
|
|
|
|
}
|
|
|
|
return onions;
|
|
|
|
}
|