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

Function hsm_secret_arg

lightningd/options.c:1305–1346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1303}
1304
1305char *hsm_secret_arg(const tal_t *ctx,
1306 const char *arg,
1307 const struct hsm_secret **hsm_secret)
1308{
1309 char *codex32_fail;
1310 struct codex32 *codex32;
1311 struct hsm_secret *hsms = tal(tmpctx, struct hsm_secret);
1312
1313 /* We accept hex, or codex32. hex is very very very unlikely to
1314 * give a valid codex32, so try that first */
1315 codex32 = codex32_decode(tmpctx, "cl", arg, &codex32_fail);
1316 if (codex32) {
1317 hsms->type = HSM_SECRET_PLAIN;
1318 hsms->secret_data = tal_steal(hsms, codex32->payload);
1319 if (codex32->threshold != 0
1320 || codex32->type != CODEX32_ENCODING_SECRET) {
1321 return "This is only one share of codex32!";
1322 }
1323 if (tal_count(hsms->secret_data) != 32)
1324 return "Invalid length: must be 32 bytes";
1325 /* Not codex32, was it hex? */
1326 } else if ((hsms->secret_data = tal_hexdata(hsms, arg, strlen(arg))) != NULL) {
1327 hsms->type = HSM_SECRET_PLAIN;
1328 if (tal_count(hsms->secret_data) != 32)
1329 return "Invalid length: must be 32 bytes";
1330 /* Not hex, is is a mnemonic? */
1331 } else {
1332 enum hsm_secret_error err = validate_mnemonic(arg);
1333 if (err != HSM_SECRET_OK) {
1334 /* If it looks kinda like a codex32, give that error. */
1335 if (strstarts(arg, "cl"))
1336 return codex32_fail;
1337 else
1338 return "Not a valid mnemonic, hex, or codex32 string";
1339 }
1340 hsms->type = HSM_SECRET_MNEMONIC_NO_PASS;
1341 hsms->mnemonic = tal_strdup(hsms, arg);
1342 }
1343
1344 *hsm_secret = tal_steal(ctx, hsms);
1345 return NULL;
1346}
1347
1348static char *opt_set_hsm_secret(const char *arg, struct lightningd *ld)
1349{

Callers 2

opt_set_hsm_secretFunction · 0.70
param_hsm_secretFunction · 0.70

Calls 3

codex32_decodeFunction · 0.85
tal_hexdataFunction · 0.85
validate_mnemonicFunction · 0.85

Tested by

no test coverage detected