Skip to content

Commit

Permalink
devtools/blindedpath: implement scid support.
Browse files Browse the repository at this point in the history
This is what we expect in an enctlv used for htlcs.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Apr 5, 2020
1 parent 35a93dc commit 0f9bc8e
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions devtools/blindedpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int main(int argc, char **argv)
if (streq(argv[1], "create")) {
struct privkey e;
struct pubkey *pk_e, *b, *nodes;
struct short_channel_id **scids;
struct secret *rho;
size_t num = argc - 2;

Expand All @@ -91,6 +92,7 @@ int main(int argc, char **argv)
/* rho(i) */
rho = tal_arr(tmpctx, struct secret, num);

scids = tal_arr(tmpctx, struct short_channel_id *, num);
/* Randomness, chosen with a fair dice roll! */
memset(&e, 6, sizeof(e));
if (!pubkey_from_privkey(&e, &pk_e[0]))
Expand All @@ -100,12 +102,23 @@ int main(int argc, char **argv)
struct secret ss;
struct secret hmac;
struct sha256 h;
const char *slash;

if (!pubkey_from_hexstr(argv[2+i],
strcspn(argv[2+i], "/"),
&nodes[i]))
errx(1, "%s not a valid pubkey", argv[2+i]);

slash = strchr(argv[2+i], '/');
if (slash) {
scids[i] = tal(scids, struct short_channel_id);
if (!short_channel_id_from_str(slash+1,
strlen(slash+1),
scids[i]))
errx(1, "%s is not a valid scids",
slash + 1);
} else
scids[i] = NULL;
if (secp256k1_ecdh(secp256k1_ctx, ss.data,
&nodes[i].pubkey, e.secret.data, NULL, NULL) != 1)
abort();
Expand Down Expand Up @@ -142,9 +155,16 @@ int main(int argc, char **argv)

/* Inner is encrypted */
inner = tlv_onionmsg_payload_new(tmpctx);
/* FIXME: Use /scid for encblob if specified */
inner->next_node_id = tal(inner, struct tlv_onionmsg_payload_next_node_id);
inner->next_node_id->node_id = nodes[i+1];
/* Use scid if they provided one */
if (scids[i]) {
inner->next_short_channel_id
= tal(inner, struct tlv_onionmsg_payload_next_short_channel_id);
inner->next_short_channel_id->short_channel_id
= *scids[i];
} else {
inner->next_node_id = tal(inner, struct tlv_onionmsg_payload_next_node_id);
inner->next_node_id->node_id = nodes[i+1];
}
p = tal_arr(tmpctx, u8, 0);
towire_encmsg_tlvs(&p, inner);

Expand Down

0 comments on commit 0f9bc8e

Please sign in to comment.