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

Function json_makesecret

lightningd/hsm_control.c:129–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127}
128
129static struct command_result *json_makesecret(struct command *cmd,
130 const char *buffer,
131 const jsmntok_t *obj UNNEEDED,
132 const jsmntok_t *params)
133{
134 u8 *data;
135 const char *strdata;
136 struct json_stream *response;
137 struct secret secret;
138
139 if (!param(cmd, buffer, params,
140 p_opt("hex", param_bin_from_hex, &data),
141 p_opt("string", param_string, &strdata),
142 NULL))
143 return command_param_failed();
144
145 if (strdata) {
146 if (data)
147 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
148 "Cannot have both hex and string");
149 data = tal_dup_arr(cmd, u8, (u8 *)strdata, strlen(strdata), 0);
150 } else {
151 if (!data)
152 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
153 "Must have either hex or string");
154 }
155
156
157 u8 *msg = towire_hsmd_derive_secret(cmd, data);
158 if (!wire_sync_write(cmd->ld->hsm_fd, take(msg)))
159 return command_fail(cmd, LIGHTNINGD,
160 "Could not write to HSM: %s", strerror(errno));
161
162
163 msg = wire_sync_read(tmpctx, cmd->ld->hsm_fd);
164 if (!fromwire_hsmd_derive_secret_reply(msg, &secret))
165 return command_fail(cmd, LIGHTNINGD,
166 "Bad reply from HSM: %s", strerror(errno));
167
168
169 response = json_stream_success(cmd);
170 json_add_secret(response, "secret", &secret);
171 return command_success(cmd, response);
172}
173
174static const struct json_command makesecret_command = {
175 "makesecret",

Callers

nothing calls this directly

Calls 8

command_param_failedFunction · 0.70
command_failFunction · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70
paramFunction · 0.50
wire_sync_writeFunction · 0.50
wire_sync_readFunction · 0.50
json_add_secretFunction · 0.50

Tested by

no test coverage detected