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

Function main

tools/lightning-hsmtool.c:668–819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

666}
667
668int main(int argc, char *argv[])
669{
670 const char *method;
671
672 setup_locale();
673 err_set_progname(argv[0]);
674 secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
675 | SECP256K1_CONTEXT_SIGN);
676
677 method = argc > 1 ? argv[1] : NULL;
678 if (!method)
679 show_usage(argv[0]);
680
681 if (streq(method, "decrypt")) {
682 if (argc < 3)
683 show_usage(argv[0]);
684 decrypt_hsm(argv[2]);
685 } else if (streq(method, "encrypt")) {
686 if (argc < 3)
687 show_usage(argv[0]);
688 encrypt_hsm(argv[2]);
689
690 } else if (streq(method, "dumpcommitments")) {
691 /* node_id channel_id depth hsm_secret */
692 if (argc < 6)
693 show_usage(argv[0]);
694 struct node_id node_id;
695 if (!node_id_from_hexstr(argv[2], strlen(argv[2]), &node_id))
696 errx(ERROR_USAGE, "Bad node id");
697 dump_commitments_infos(&node_id, atol(argv[3]), atol(argv[4]),
698 argv[5]);
699
700 } else if (streq(method, "guesstoremote")) {
701 /* address node_id depth hsm_secret */
702 if (argc < 6)
703 show_usage(argv[0]);
704 struct node_id node_id;
705 if (!node_id_from_hexstr(argv[3], strlen(argv[3]), &node_id))
706 errx(ERROR_USAGE, "Bad node id");
707 guess_to_remote(argv[2], &node_id, atol(argv[4]),
708 argv[5]);
709
710 } else if (streq(method, "derivetoremote")) {
711 /* node_id channel_id [commitment_point] hsm_secret */
712 if (argc < 5 || argc > 6)
713 show_usage(argv[0]);
714 struct unilateral_close_info info = { };
715 struct pubkey commitment_point;
716 if (!node_id_from_hexstr(argv[2], strlen(argv[2]), &info.peer_id))
717 errx(ERROR_USAGE, "Bad node id");
718 info.channel_id = atoll(argv[3]);
719 if (argc == 6) {
720 if (!pubkey_from_hexstr(argv[4], strlen(argv[4]), &commitment_point))
721 errx(ERROR_USAGE, "Bad commitment point");
722 info.commitment_point = &commitment_point;
723 }
724 derive_to_remote(&info, argv[argc - 1]);
725

Callers

nothing calls this directly

Calls 15

setup_localeFunction · 0.85
err_set_prognameFunction · 0.85
show_usageFunction · 0.85
decrypt_hsmFunction · 0.85
encrypt_hsmFunction · 0.85
errxFunction · 0.85
dump_commitments_infosFunction · 0.85
guess_to_remoteFunction · 0.85
pubkey_from_hexstrFunction · 0.85
derive_to_remoteFunction · 0.85
generate_hsmFunction · 0.85
dumponchaindescriptorsFunction · 0.85

Tested by

no test coverage detected