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-03-31 05:13:27 +02:00
|
|
|
enum onion_payload_type {
|
|
|
|
ONION_V0_PAYLOAD = 0,
|
|
|
|
ONION_TLV_PAYLOAD = 1,
|
|
|
|
};
|
|
|
|
|
2019-12-05 11:06:28 +01:00
|
|
|
struct onion_payload {
|
2022-03-31 05:13:27 +02:00
|
|
|
enum onion_payload_type type;
|
|
|
|
|
2019-12-05 11:06:28 +01:00
|
|
|
struct amount_msat amt_to_forward;
|
|
|
|
u32 outgoing_cltv;
|
|
|
|
struct amount_msat *total_msat;
|
|
|
|
struct short_channel_id *forward_channel;
|
|
|
|
struct secret *payment_secret;
|
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
|
|
|
|
|
|
|
/* Note that this can fail if we supply payment_secret and !use_tlv! */
|
|
|
|
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,
|
2019-12-05 11:06:28 +01:00
|
|
|
const struct secret *payment_secret);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* onion_payload_length: measure payload length in decrypted onion.
|
|
|
|
* @raw_payload: payload to look at.
|
|
|
|
* @len: length of @raw_payload in bytes.
|
2020-03-12 00:59:01 +01:00
|
|
|
* @has_realm: used for HTLCs, where first byte 0 is magical.
|
2019-12-05 11:06:28 +01:00
|
|
|
* @valid: set to true if it is valid, false otherwise.
|
2022-03-31 05:13:27 +02:00
|
|
|
* @type: if non-NULL, set to type of payload if *@valid is true.
|
2019-12-05 11:06:28 +01:00
|
|
|
*
|
|
|
|
* If @valid is set, there is room for the HMAC immediately following,
|
|
|
|
* as the return value is <= ROUTING_INFO_SIZE - HMAC_SIZE. Otherwise,
|
|
|
|
* the return value is @len (i.e. the entire payload).
|
|
|
|
*/
|
|
|
|
size_t onion_payload_length(const u8 *raw_payload, size_t len,
|
2020-03-12 00:59:01 +01:00
|
|
|
bool has_realm,
|
2022-03-31 05:13:27 +02:00
|
|
|
bool *valid,
|
|
|
|
enum onion_payload_type *type);
|
2019-12-05 11:06:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* onion_decode: decode payload from a decrypted onion.
|
|
|
|
* @ctx: context to allocate onion_contents off.
|
|
|
|
* @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.
|
|
|
|
* @blinding_ss: the shared secret derived from @blinding (iff that's non-NULL)
|
2021-06-17 13:00:24 +02:00
|
|
|
* @accepted_extra_tlvs: Allow these types to be in the TLV without failing
|
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,
|
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,
|
|
|
|
const struct secret *blinding_ss,
|
2022-03-23 03:44:38 +01:00
|
|
|
const u64 *accepted_extra_tlvs,
|
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 */
|