| 19 | } |
| 20 | |
| 21 | static void do_generate(int argc, char **argv, |
| 22 | const u8 *assocdata, |
| 23 | const struct node_id *rvnode_id) |
| 24 | { |
| 25 | const tal_t *ctx = talz(NULL, tal_t); |
| 26 | int num_hops = argc - 2; |
| 27 | struct pubkey *path = tal_arr(ctx, struct pubkey, num_hops); |
| 28 | u8 rawprivkey[PRIVKEY_LEN]; |
| 29 | struct secret session_key; |
| 30 | struct secret *shared_secrets; |
| 31 | struct sphinx_path *sp; |
| 32 | struct sphinx_compressed_onion *comp; |
| 33 | u8 *serialized; |
| 34 | struct onionpacket *packet; |
| 35 | |
| 36 | memset(&session_key, 'A', sizeof(struct secret)); |
| 37 | |
| 38 | sp = sphinx_path_new_with_key(ctx, assocdata, &session_key); |
| 39 | sphinx_path_set_rendezvous(sp, rvnode_id); |
| 40 | |
| 41 | for (int i = 0; i < num_hops; i++) { |
| 42 | size_t klen = strcspn(argv[2 + i], "/"); |
| 43 | if (hex_data_size(klen) == PRIVKEY_LEN) { |
| 44 | if (!hex_decode(argv[2 + i], klen, rawprivkey, PRIVKEY_LEN)) |
| 45 | errx(1, "Invalid private key hex '%s'", |
| 46 | argv[2 + i]); |
| 47 | |
| 48 | if (secp256k1_ec_pubkey_create(secp256k1_ctx, |
| 49 | &path[i].pubkey, |
| 50 | rawprivkey) != 1) |
| 51 | errx(1, "Could not decode pubkey"); |
| 52 | } else if (hex_data_size(klen) == PUBKEY_CMPR_LEN) { |
| 53 | if (!pubkey_from_hexstr(argv[2 + i], klen, &path[i])) |
| 54 | errx(1, "Invalid public key hex '%s'", |
| 55 | argv[2 + i]); |
| 56 | } else { |
| 57 | errx(1, |
| 58 | "Provided key is neither a pubkey nor a privkey: " |
| 59 | "%s\n", |
| 60 | argv[2 + i]); |
| 61 | } |
| 62 | |
| 63 | /* /<hex> -> raw hopdata. /tlv -> TLV encoding. */ |
| 64 | if (argv[2 + i][klen] != '\0' && argv[2 + i][klen] != 't') { |
| 65 | const char *hopstr = argv[2 + i] + klen + 1; |
| 66 | u8 *data = tal_hexdata(ctx, hopstr, strlen(hopstr)); |
| 67 | |
| 68 | if (!data) |
| 69 | errx(1, "bad hex after / in %s", argv[1 + i]); |
| 70 | sphinx_add_hop_has_length(sp, &path[i], data); |
| 71 | } else { |
| 72 | struct short_channel_id scid; |
| 73 | struct amount_msat amt; |
| 74 | |
| 75 | /* FIXME: support secret and and total_msat */ |
| 76 | memset(&scid, i, sizeof(scid)); |
| 77 | amt = amount_msat(i); |
| 78 | if (i == num_hops - 1) |
no test coverage detected