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

Function json_makesecret

lightningd/hsm_control.c:317–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

315}
316
317static struct command_result *json_makesecret(struct command *cmd,
318 const char *buffer,
319 const jsmntok_t *obj UNNEEDED,
320 const jsmntok_t *params)
321{
322 u8 *data;
323 const char *strdata;
324 struct json_stream *response;
325 struct secret secret;
326
327 if (!param_check(cmd, buffer, params,
328 p_opt("hex", param_bin_from_hex, &data),
329 p_opt("string", param_string, &strdata),
330 NULL))
331 return command_param_failed();
332
333 if (strdata) {
334 if (data)
335 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
336 "Cannot have both hex and string");
337 data = tal_dup_arr(cmd, u8, (u8 *)strdata, strlen(strdata), 0);
338 } else {
339 if (!data)
340 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
341 "Must have either hex or string");
342 }
343
344 if (command_check_only(cmd))
345 return command_check_done(cmd);
346
347 u8 *msg = towire_hsmd_derive_secret(cmd, data);
348 if (!wire_sync_write(cmd->ld->hsm_fd, take(msg)))
349 return command_fail(cmd, LIGHTNINGD,
350 "Could not write to HSM: %s", strerror(errno));
351
352
353 msg = wire_sync_read(tmpctx, cmd->ld->hsm_fd);
354 if (!fromwire_hsmd_derive_secret_reply(msg, &secret))
355 return command_fail(cmd, LIGHTNINGD,
356 "Bad reply from HSM: %s", strerror(errno));
357
358
359 response = json_stream_success(cmd);
360 json_add_secret(response, "secret", &secret);
361 return command_success(cmd, response);
362}
363
364static const struct json_command makesecret_command = {
365 "makesecret",

Callers

nothing calls this directly

Calls 12

param_checkFunction · 0.85
json_add_secretFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70
wire_sync_writeFunction · 0.50
wire_sync_readFunction · 0.50

Tested by

no test coverage detected