diff --git a/common/blindedpath.c b/common/blindedpath.c index 939be49a8..687d2e21b 100644 --- a/common/blindedpath.c +++ b/common/blindedpath.c @@ -256,8 +256,12 @@ u8 *create_enctlv(const tal_t *ctx, const struct privkey *blinding, const struct pubkey *node, const struct pubkey *next_node, + const struct short_channel_id *next_scid, size_t padlen, const struct pubkey *next_blinding_override, + const struct tlv_encrypted_data_tlv_payment_relay *payment_relay TAKES, + const struct tlv_encrypted_data_tlv_payment_constraints *payment_constraints TAKES, + const u8 *allowed_features TAKES, struct privkey *next_blinding, struct pubkey *node_alias) { @@ -266,6 +270,11 @@ u8 *create_enctlv(const tal_t *ctx, encmsg->padding = tal_arrz(encmsg, u8, padlen); encmsg->next_node_id = cast_const(struct pubkey *, next_node); encmsg->next_blinding_override = cast_const(struct pubkey *, next_blinding_override); + encmsg->payment_relay = tal_dup_or_null(encmsg, struct tlv_encrypted_data_tlv_payment_relay, + payment_relay); + encmsg->payment_constraints = tal_dup_or_null(encmsg, struct tlv_encrypted_data_tlv_payment_constraints, + payment_constraints); + encmsg->allowed_features = tal_dup_talarr(encmsg, u8, allowed_features); return enctlv_from_encmsg(ctx, blinding, node, encmsg, next_blinding, node_alias); @@ -276,6 +285,7 @@ u8 *create_final_enctlv(const tal_t *ctx, const struct pubkey *final_node, size_t padlen, const struct secret *path_id, + const u8 *allowed_features TAKES, struct pubkey *node_alias) { struct tlv_encrypted_data_tlv *encmsg = tlv_encrypted_data_tlv_new(tmpctx); @@ -285,6 +295,7 @@ u8 *create_final_enctlv(const tal_t *ctx, encmsg->padding = tal_arrz(encmsg, u8, padlen); if (path_id) encmsg->path_id = (u8 *)tal_dup(encmsg, struct secret, path_id); + encmsg->allowed_features = tal_dup_talarr(encmsg, u8, allowed_features); return enctlv_from_encmsg(ctx, blinding, final_node, encmsg, &unused_next_blinding, node_alias); diff --git a/common/blindedpath.h b/common/blindedpath.h index 3bf092ba6..6827d10a5 100644 --- a/common/blindedpath.h +++ b/common/blindedpath.h @@ -9,6 +9,9 @@ struct route_info; struct pubkey; struct privkey; struct secret; +struct short_channel_id; +struct tlv_encrypted_data_tlv_payment_constraints; +struct tlv_encrypted_data_tlv_payment_relay; /** * create_enctlv - Encrypt an encmsg to form an enctlv. @@ -16,22 +19,31 @@ struct secret; * @blinding: e(i), the blinding secret * @node: the pubkey of the node to encrypt for * @next_node: the pubkey of the next node, to place in enctlv + * @next_scid: the short_channel_id to the next node, to place in enctlv * @padlen: if non-zero, the bytes of padding to add (also adds 2 byte padding hdr) * @next_blinding_override: the optional blinding point to place in enctlv + * @payment_relay: optional payment_relay tlv + * @payment_constraints: optional payment_constraints tlv + * @allowed_features: optional allowed_features array * @next_blinding: (out) e(i+1), the next blinding secret. * @node_alias: (out) the blinded pubkey of the node to tell the recipient. * + * Exactly one of next_node and next_scid must be non-NULL. * Returns the enctlv blob, or NULL if the secret is invalid. */ u8 *create_enctlv(const tal_t *ctx, const struct privkey *blinding, const struct pubkey *node, const struct pubkey *next_node, + const struct short_channel_id *next_scid, size_t padlen, const struct pubkey *next_blinding_override, + const struct tlv_encrypted_data_tlv_payment_relay *payment_relay TAKES, + const struct tlv_encrypted_data_tlv_payment_constraints *payment_constraints TAKES, + const u8 *allowed_features TAKES, struct privkey *next_blinding, struct pubkey *node_alias) - NON_NULL_ARGS(2, 3, 4, 7, 8); + NON_NULL_ARGS(2, 3, 11, 12); /** * create_final_enctlv - Encrypt an encmsg to form the final enctlv. @@ -39,6 +51,7 @@ u8 *create_enctlv(const tal_t *ctx, * @blinding: e(i), the blinding secret * @final_node: the pubkey of the node to encrypt for * @padlen: if non-zero, the bytes of padding to add (also adds 2 byte padding hdr) + * @allowed_features: optional allowed_features array * @path_id: secret to include in enctlv, if not NULL. * @node_alias: (out) the blinded pubkey of the node to tell the recipient. * @@ -49,8 +62,9 @@ u8 *create_final_enctlv(const tal_t *ctx, const struct pubkey *final_node, size_t padlen, const struct secret *path_id, + const u8 *allowed_features TAKES, struct pubkey *node_alias) - NON_NULL_ARGS(2, 3, 6); + NON_NULL_ARGS(2, 3, 7); /** * unblind_onion - tweak onion epheremeral key so we can decode it with ours. diff --git a/common/test/run-blindedpath_enctlv.c b/common/test/run-blindedpath_enctlv.c index 5f30c9fd6..58d28c666 100644 --- a/common/test/run-blindedpath_enctlv.c +++ b/common/test/run-blindedpath_enctlv.c @@ -171,8 +171,8 @@ int main(int argc, char *argv[]) "\t},\n", type_to_string(tmpctx, struct pubkey, &bob_id)); - enctlv = create_enctlv(tmpctx, &blinding, &alice_id, &bob_id, - 0, NULL, &blinding, &alias); + enctlv = create_enctlv(tmpctx, &blinding, &alice_id, &bob_id, NULL, + 0, NULL, NULL, NULL, NULL, &blinding, &alias); printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n" "},\n", tal_hex(tmpctx, enctlv)); @@ -201,8 +201,9 @@ int main(int argc, char *argv[]) type_to_string(tmpctx, struct pubkey, &carol_id), type_to_string(tmpctx, struct privkey, &override_blinding)); - enctlv = create_enctlv(tmpctx, &blinding, &bob_id, &carol_id, - 0, &override_blinding_pub, &blinding, &alias); + enctlv = create_enctlv(tmpctx, &blinding, &bob_id, &carol_id, NULL, + 0, &override_blinding_pub, NULL, NULL, NULL, + &blinding, &alias); printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n" "},\n", tal_hex(tmpctx, enctlv)); @@ -230,8 +231,8 @@ int main(int argc, char *argv[]) type_to_string(tmpctx, struct pubkey, &dave_id), tal_hex(tmpctx, tal_arrz(tmpctx, u8, 35))); - enctlv = create_enctlv(tmpctx, &blinding, &carol_id, &dave_id, - 35, NULL, &blinding, &alias); + enctlv = create_enctlv(tmpctx, &blinding, &carol_id, &dave_id, NULL, + 35, NULL, NULL, NULL, NULL, &blinding, &alias); printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n" "},\n", tal_hex(tmpctx, enctlv)); @@ -256,7 +257,7 @@ int main(int argc, char *argv[]) type_to_string(tmpctx, struct secret, &self_id)); enctlv = create_final_enctlv(tmpctx, &blinding, &dave_id, - 0, &self_id, &alias); + 0, &self_id, NULL, &alias); printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n", tal_hex(tmpctx, enctlv)); diff --git a/common/test/run-blindedpath_onion.c b/common/test/run-blindedpath_onion.c index db7f7fe53..b3b0c752e 100644 --- a/common/test/run-blindedpath_onion.c +++ b/common/test/run-blindedpath_onion.c @@ -170,8 +170,9 @@ int main(int argc, char *argv[]) pubkey_from_privkey(&blinding[ALICE], &blinding_pub[ALICE]); enctlv[ALICE] = create_enctlv(tmpctx, &blinding[ALICE], - &id[ALICE], &id[BOB], - 0, NULL, &blinding[BOB], &alias[ALICE]); + &id[ALICE], &id[BOB], NULL, + 0, NULL, NULL, NULL, NULL, + &blinding[BOB], &alias[ALICE]); pubkey_from_privkey(&blinding[BOB], &blinding_pub[BOB]); @@ -179,8 +180,8 @@ int main(int argc, char *argv[]) memset(&override_blinding, 7, sizeof(override_blinding)); pubkey_from_privkey(&override_blinding, &override_blinding_pub); enctlv[BOB] = create_enctlv(tmpctx, &blinding[BOB], - &id[BOB], &id[CAROL], - 0, &override_blinding_pub, + &id[BOB], &id[CAROL], NULL, + 0, &override_blinding_pub, NULL, NULL, NULL, &blinding[CAROL], &alias[BOB]); /* That replaced the blinding */ @@ -188,14 +189,15 @@ int main(int argc, char *argv[]) blinding_pub[CAROL] = override_blinding_pub; enctlv[CAROL] = create_enctlv(tmpctx, &blinding[CAROL], - &id[CAROL], &id[DAVE], - 35, NULL, &blinding[DAVE], &alias[CAROL]); + &id[CAROL], &id[DAVE], NULL, + 35, NULL, NULL, NULL, NULL, + &blinding[DAVE], &alias[CAROL]); for (size_t i = 0; i < sizeof(self_id); i++) self_id.data[i] = i+1; enctlv[DAVE] = create_final_enctlv(tmpctx, &blinding[DAVE], &id[DAVE], - 0, &self_id, &alias[DAVE]); + 0, &self_id, NULL, &alias[DAVE]); pubkey_from_privkey(&blinding[DAVE], &blinding_pub[DAVE]); /* Create an onion which encodes this. */ diff --git a/lightningd/onion_message.c b/lightningd/onion_message.c index 26f951995..666ce78f3 100644 --- a/lightningd/onion_message.c +++ b/lightningd/onion_message.c @@ -336,10 +336,10 @@ static struct command_result *json_blindedpath(struct command *cmd, path[i]->encrypted_recipient_data = create_enctlv(path[i], &blinding_iter, &ids[i], - &ids[i+1], + &ids[i+1], NULL, /* FIXME: Pad? */ 0, - NULL, + NULL, NULL, NULL, NULL, &blinding_iter, &path[i]->node_id); } @@ -352,6 +352,7 @@ static struct command_result *json_blindedpath(struct command *cmd, /* FIXME: Pad? */ 0, &cmd->ld->onion_reply_secret, + NULL, &path[nhops-1]->node_id); response = json_stream_success(cmd); diff --git a/plugins/fetchinvoice.c b/plugins/fetchinvoice.c index 8ecf9c41e..fd54d90ee 100644 --- a/plugins/fetchinvoice.c +++ b/plugins/fetchinvoice.c @@ -638,9 +638,10 @@ send_modern_message(struct command *cmd, &blinding_iter, &sent->path[i], &sent->path[i+1], + NULL, /* FIXME: Pad? */ 0, - NULL, + NULL, NULL, NULL, NULL, &blinding_iter, &node_alias[i]); } @@ -650,7 +651,7 @@ send_modern_message(struct command *cmd, /* We don't include enctlv in final, but it gives us final alias */ if (!create_final_enctlv(tmpctx, &blinding_iter, &sent->path[nhops-1], /* FIXME: Pad? */ 0, - NULL, + NULL, NULL, &node_alias[nhops-1])) { /* Should not happen! */ return command_fail(cmd, LIGHTNINGD,