From 55f0515d20f56daf42fc4e054689922743764ad1 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Fri, 30 Jun 2023 21:56:16 +0200 Subject: [PATCH] hsmtool: Add support for Signet network This commit addresses a limitation in our CLI argument checking for the hsmtool. With this update, we introduce support for the Signet network. In addition, it introduce a code semplification by directly passing the BIP32 version instead of using network testnet flag. This change improves code readability and minimaze code changes to support other networks. Link: https://github.com/ElementsProject/lightning/issues/6371 Reported-by: @grubles Changelog-Fixes: hsmtool: Add support for Signet network Signed-off-by: Vincenzo Palazzo --- tools/hsmtool.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/hsmtool.c b/tools/hsmtool.c index d2217a73b..7575eab2d 100644 --- a/tools/hsmtool.c +++ b/tools/hsmtool.c @@ -529,13 +529,11 @@ static int generate_hsm(const char *hsm_secret_path) } static int dumponchaindescriptors(const char *hsm_secret_path, const char *old_passwd UNUSED, - const bool is_testnet) + const u32 version) { struct secret hsm_secret; u8 bip32_seed[BIP32_ENTROPY_LEN_256]; u32 salt = 0; - u32 version = is_testnet ? - BIP32_VER_TEST_PRIVATE : BIP32_VER_MAIN_PRIVATE; struct ext_key master_extkey; char *enc_xpub, *descriptor; struct descriptor_checksum checksum; @@ -715,7 +713,7 @@ int main(int argc, char *argv[]) if (streq(method, "dumponchaindescriptors")) { char *net = NULL; - bool is_testnet; + u32 version; if (argc < 3) show_usage(argv[0]); @@ -723,16 +721,16 @@ int main(int argc, char *argv[]) if (argc > 3) net = argv[3]; - if (net && streq(net, "testnet")) - is_testnet = true; + if (net && (streq(net, "testnet") || streq(net, "signet"))) + version = BIP32_VER_TEST_PRIVATE; else if (net && !streq(net, "bitcoin")) errx(ERROR_USAGE, "Network '%s' not supported." " Supported networks: bitcoin (default)," - " testnet", net); + " testnet and signet", net); else - is_testnet = false; + version = BIP32_VER_MAIN_PRIVATE; - return dumponchaindescriptors(argv[2], NULL, is_testnet); + return dumponchaindescriptors(argv[2], NULL, version); } if (streq(method, "checkhsm")) {