|
|
@ -28,6 +28,7 @@ static void do_generate(int argc, char **argv) |
|
|
|
if (secp256k1_ec_pubkey_create(secp256k1_ctx, &path[i].pubkey, |
|
|
|
privkeys[i]) != 1) |
|
|
|
errx(1, "Could not decode pubkey"); |
|
|
|
printf("Node %d pubkey %s\n", i, secp256k1_pubkey_to_hexstr(ctx, &path[i].pubkey)); |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < num_hops; i++) { |
|
|
@ -47,10 +48,9 @@ static void do_generate(int argc, char **argv) |
|
|
|
u8 *serialized = serialize_onionpacket(ctx, res); |
|
|
|
if (!serialized) |
|
|
|
errx(1, "Error serializing message."); |
|
|
|
|
|
|
|
char hextemp[2 * tal_count(serialized) + 1]; |
|
|
|
hex_encode(serialized, tal_count(serialized), hextemp, sizeof(hextemp)); |
|
|
|
printf("%s\n", hextemp); |
|
|
|
else |
|
|
|
printf("%s\n", tal_hex(ctx, serialized)); |
|
|
|
tal_free(ctx); |
|
|
|
} |
|
|
|
|
|
|
|
static void do_decode(int argc, char **argv) |
|
|
@ -65,15 +65,21 @@ static void do_decode(int argc, char **argv) |
|
|
|
u8 shared_secret[32]; |
|
|
|
u8 assocdata[32]; |
|
|
|
|
|
|
|
memset(&assocdata, 'B', sizeof(assocdata)); |
|
|
|
|
|
|
|
if (argc != 2) |
|
|
|
opt_usage_exit_fail("Expect a privkey with --decode"); |
|
|
|
|
|
|
|
if (!hex_decode(argv[1], strlen(argv[1]), &seckey, sizeof(seckey))) |
|
|
|
errx(1, "Invalid private key hex '%s'", argv[1]); |
|
|
|
|
|
|
|
if (!read_all(STDIN_FILENO, hextemp, sizeof(hextemp))) |
|
|
|
errx(1, "Reading in onion"); |
|
|
|
|
|
|
|
hex_decode(hextemp, sizeof(hextemp), serialized, sizeof(serialized)); |
|
|
|
|
|
|
|
msg = parse_onionpacket(ctx, serialized, sizeof(serialized)); |
|
|
|
|
|
|
|
if (!msg) |
|
|
|
errx(1, "Error parsing message."); |
|
|
|
|
|
|
@ -83,15 +89,15 @@ static void do_decode(int argc, char **argv) |
|
|
|
step = process_onionpacket(ctx, msg, shared_secret, assocdata, |
|
|
|
sizeof(assocdata)); |
|
|
|
|
|
|
|
if (!step->next) |
|
|
|
if (!step || !step->next) |
|
|
|
errx(1, "Error processing message."); |
|
|
|
|
|
|
|
u8 *ser = serialize_onionpacket(ctx, step->next); |
|
|
|
if (!ser) |
|
|
|
errx(1, "Error serializing message."); |
|
|
|
|
|
|
|
hex_encode(ser, tal_count(ser), hextemp, sizeof(hextemp)); |
|
|
|
printf("%s\n", hextemp); |
|
|
|
printf("%s\n", tal_hex(ctx, ser)); |
|
|
|
tal_free(ctx); |
|
|
|
} |
|
|
|
|
|
|
|
int main(int argc, char **argv) |
|
|
|