Skip to content

Commit

Permalink
tools/hsmtool: Add getcodexsecret to get the hsm_secret in bip93
Browse files Browse the repository at this point in the history
  • Loading branch information
adi2011 committed Jul 31, 2023
1 parent 822ae20 commit 86657d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tools/headerversions: $(FORCE) tools/headerversions.o libccan.a
tools/headerversions.o: ccan/config.h
tools/check-bolt: tools/check-bolt.o $(TOOLS_COMMON_OBJS)

tools/hsmtool: tools/hsmtool.o $(TOOLS_COMMON_OBJS) $(BITCOIN_OBJS) common/amount.o common/autodata.o common/bech32.o common/bigsize.o common/configdir.o common/configvar.o common/derive_basepoints.o common/descriptor_checksum.o common/hsm_encryption.o common/node_id.o common/type_to_string.o common/version.o wire/fromwire.o wire/towire.o
tools/hsmtool: tools/hsmtool.o $(TOOLS_COMMON_OBJS) $(BITCOIN_OBJS) common/amount.o common/autodata.o common/bech32.o common/bigsize.o common/codex32.o common/configdir.o common/configvar.o common/derive_basepoints.o common/descriptor_checksum.o common/hsm_encryption.o common/node_id.o common/type_to_string.o common/version.o wire/fromwire.o wire/towire.o

tools/lightning-hsmtool: tools/hsmtool
cp $< $@
Expand Down
18 changes: 18 additions & 0 deletions tools/hsmtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <ccan/tal/path/path.h>
#include <ccan/tal/str/str.h>
#include <common/bech32.h>
#include <common/codex32.h>
#include <common/configdir.h>
#include <common/derive_basepoints.h>
#include <common/descriptor_checksum.h>
Expand Down Expand Up @@ -44,6 +45,7 @@ static void show_usage(const char *progname)
printf(" - checkhsm <path/to/new/hsm_secret>\n");
printf(" - dumponchaindescriptors <path/to/hsm_secret> [network]\n");
printf(" - makerune <path/to/hsm_secret>\n");
printf(" - getcodexsecret <path/to/hsm_secret> <id> <threshold>\n");
exit(0);
}

Expand Down Expand Up @@ -244,6 +246,17 @@ static int decrypt_hsm(const char *hsm_secret_path)
return 0;
}

static int make_codexsecret(const char *hsm_secret_path,
const char *id,
const u32 threshold)
{
struct secret hsm_secret;
get_hsm_secret(&hsm_secret, hsm_secret_path);
printf("Codex32 Secret of your hsm_secret is: %s\n",
codex32_secret_encode(tmpctx, id, threshold, hsm_secret.data, 32));
return 0;
}

static int encrypt_hsm(const char *hsm_secret_path)
{
int fd;
Expand Down Expand Up @@ -745,5 +758,10 @@ int main(int argc, char *argv[])
return make_rune(argv[2]);
}

if(streq(method, "getcodexsecret")) {
if (argc < 3)
show_usage(argv[0]);
return make_codexsecret(argv[2], argv[3], atol(argv[4]));
}
show_usage(argv[0]);
}

0 comments on commit 86657d8

Please sign in to comment.