MCPcopy Create free account
hub / github.com/ElementsProject/lightning / do_generate

Function do_generate

devtools/onion.c:22–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.85

Calls 15

sphinx_path_new_with_keyFunction · 0.85
tal_bytelenFunction · 0.85
hex_data_sizeFunction · 0.85
hex_decodeFunction · 0.85
errxFunction · 0.85
pubkey_from_hexstrFunction · 0.85
tal_hexdataFunction · 0.85
onion_final_hopFunction · 0.85
onion_nonfinal_hopFunction · 0.85
create_onionpacketFunction · 0.85

Tested by

no test coverage detected