2019-12-05 11:06:28 +01:00
|
|
|
#ifndef LIGHTNING_COMMON_ONION_H
|
|
|
|
#define LIGHTNING_COMMON_ONION_H
|
|
|
|
#include "config.h"
|
2020-04-11 04:52:51 +02:00
|
|
|
#include <bitcoin/privkey.h>
|
2019-12-05 11:06:28 +01:00
|
|
|
#include <common/amount.h>
|
|
|
|
|
|
|
|
struct route_step;
|
2022-10-17 02:44:38 +02:00
|
|
|
struct tlv_encrypted_data_tlv_payment_relay;
|
2019-12-05 11:06:28 +01:00
|
|
|
|
|
|
|
struct onion_payload {
|
|
|
|
struct amount_msat amt_to_forward;
|
|
|
|
u32 outgoing_cltv;
|
|
|
|
struct amount_msat *total_msat;
|
|
|
|
struct short_channel_id *forward_channel;
|
|
|
|
struct secret *payment_secret;
|
2022-03-31 11:10:50 +02:00
|
|
|
u8 *payment_metadata;
|
2020-04-11 04:52:51 +02:00
|
|
|
|
|
|
|
/* If blinding is set, blinding_ss is the shared secret.*/
|
|
|
|
struct pubkey *blinding;
|
|
|
|
struct secret blinding_ss;
|
2021-06-17 15:16:55 +02:00
|
|
|
|
|
|
|
/* The raw TLVs contained in the payload. */
|
|
|
|
struct tlv_tlv_payload *tlv;
|
2019-12-05 11:06:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
u8 *onion_nonfinal_hop(const tal_t *ctx,
|
|
|
|
const struct short_channel_id *scid,
|
|
|
|
struct amount_msat forward,
|
2020-04-11 05:23:09 +02:00
|
|
|
u32 outgoing_cltv,
|
|
|
|
const struct pubkey *blinding,
|
|
|
|
const u8 *enctlv);
|
2019-12-05 11:06:28 +01:00
|
|
|
|
2022-03-31 11:10:50 +02:00
|
|
|
/* Note that this can fail if we supply payment_secret or payment_metadata and !use_tlv! */
|
2019-12-05 11:06:28 +01:00
|
|
|
u8 *onion_final_hop(const tal_t *ctx,
|
|
|
|
struct amount_msat forward,
|
|
|
|
u32 outgoing_cltv,
|
|
|
|
struct amount_msat total_msat,
|
2020-04-11 05:23:09 +02:00
|
|
|
const struct pubkey *blinding,
|
|
|
|
const u8 *enctlv,
|
2022-03-31 11:10:50 +02:00
|
|
|
const struct secret *payment_secret,
|
|
|
|
const u8 *payment_metadata);
|
2019-12-05 11:06:28 +01:00
|
|
|
|
2022-10-17 02:44:38 +02:00
|
|
|
|
2019-12-05 11:06:28 +01:00
|
|
|
/**
|
|
|
|
* onion_decode: decode payload from a decrypted onion.
|
|
|
|
* @ctx: context to allocate onion_contents off.
|
2022-10-17 02:44:38 +02:00
|
|
|
* @blinding_support: --experimental-route-blinding?
|
2019-12-05 11:06:28 +01:00
|
|
|
* @rs: the route_step, whose raw_payload is of at least length
|
|
|
|
* onion_payload_length().
|
2020-04-11 04:52:51 +02:00
|
|
|
* @blinding: the optional incoming blinding point.
|
2021-06-17 13:00:24 +02:00
|
|
|
* @accepted_extra_tlvs: Allow these types to be in the TLV without failing
|
2022-10-17 02:44:38 +02:00
|
|
|
* @amount_in: Incoming HTLC amount
|
|
|
|
* @cltv_expiry: Incoming HTLC cltv_expiry
|
2020-04-11 04:52:51 +02:00
|
|
|
* @failtlvtype: (out) the tlv type which failed to parse.
|
|
|
|
* @failtlvpos: (out) the offset in the tlv which failed to parse.
|
2019-12-05 11:06:28 +01:00
|
|
|
*
|
|
|
|
* If the payload is not valid, returns NULL.
|
|
|
|
*/
|
|
|
|
struct onion_payload *onion_decode(const tal_t *ctx,
|
2022-10-17 02:44:38 +02:00
|
|
|
bool blinding_support,
|
2020-03-04 14:20:59 +01:00
|
|
|
const struct route_step *rs,
|
2020-04-11 04:52:51 +02:00
|
|
|
const struct pubkey *blinding,
|
2022-03-23 03:44:38 +01:00
|
|
|
const u64 *accepted_extra_tlvs,
|
2022-10-17 02:44:38 +02:00
|
|
|
struct amount_msat amount_in,
|
|
|
|
u32 cltv_expiry,
|
2020-03-04 14:20:59 +01:00
|
|
|
u64 *failtlvtype,
|
|
|
|
size_t *failtlvpos);
|
2019-12-05 11:06:28 +01:00
|
|
|
#endif /* LIGHTNING_COMMON_ONION_H */
|