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

Function json_blindedpath

lightningd/onion_message.c:292–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290}
291
292static struct command_result *json_blindedpath(struct command *cmd,
293 const char *buffer,
294 const jsmntok_t *obj UNNEEDED,
295 const jsmntok_t *params)
296{
297 struct pubkey *ids;
298 struct onionmsg_path **path;
299 struct privkey first_blinding, blinding_iter;
300 struct pubkey first_blinding_pubkey, first_node, me;
301 size_t nhops;
302 struct json_stream *response;
303
304 if (!param(cmd, buffer, params,
305 p_req("ids", param_pubkeys, &ids),
306 NULL))
307 return command_param_failed();
308
309 nhops = tal_count(ids);
310
311 /* Final id should be us! */
312 if (!pubkey_from_node_id(&me, &cmd->ld->id))
313 fatal("My id %s is invalid?",
314 type_to_string(tmpctx, struct node_id, &cmd->ld->id));
315
316 first_node = ids[0];
317 if (!pubkey_eq(&ids[nhops-1], &me))
318 return command_fail(cmd, LIGHTNINGD,
319 "Final of ids must be this node (%s), not %s",
320 type_to_string(tmpctx, struct pubkey, &me),
321 type_to_string(tmpctx, struct pubkey,
322 &ids[nhops-1]));
323
324 randombytes_buf(&first_blinding, sizeof(first_blinding));
325 if (!pubkey_from_privkey(&first_blinding, &first_blinding_pubkey))
326 /* Should not happen! */
327 return command_fail(cmd, LIGHTNINGD,
328 "Could not convert blinding to pubkey!");
329
330 /* We convert ids into aliases as we go. */
331 path = tal_arr(cmd, struct onionmsg_path *, nhops);
332
333 blinding_iter = first_blinding;
334 for (size_t i = 0; i < nhops - 1; i++) {
335 path[i] = tal(path, struct onionmsg_path);
336 path[i]->encrypted_recipient_data = create_enctlv(path[i],
337 &blinding_iter,
338 &ids[i],
339 &ids[i+1],
340 /* FIXME: Pad? */
341 0,
342 NULL,
343 &blinding_iter,
344 &path[i]->node_id);
345 }
346
347 /* FIXME: Add padding! */
348 path[nhops-1] = tal(path, struct onionmsg_path);
349 path[nhops-1]->encrypted_recipient_data = create_final_enctlv(path[nhops-1],

Callers

nothing calls this directly

Calls 12

pubkey_from_privkeyFunction · 0.85
create_enctlvFunction · 0.85
create_final_enctlvFunction · 0.85
json_add_blindedpathFunction · 0.85
command_param_failedFunction · 0.70
fatalFunction · 0.70
command_failFunction · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70
paramFunction · 0.50
pubkey_from_node_idFunction · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected