Skip to content

Commit

Permalink
hsmtool: add a 'testnet' option to 'dumponchaindescriptors'
Browse files Browse the repository at this point in the history
Actually, it's more complex to translate the xpub descriptor to
testnet because of the descriptor checksum.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
  • Loading branch information
darosior committed Nov 1, 2020
1 parent 6eef50d commit 3710c5e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tools/hsmtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void show_usage(const char *progname)
printf(" - guesstoremote <P2WPKH address> <node id> <tries> "
"<path/to/hsm_secret> [hsm_secret password]\n");
printf(" - dumponchaindescriptors <path/to/hsm_secret> [password] "
"[private]\n");
"[private] [testnet]\n");
exit(0);
}

Expand Down Expand Up @@ -373,11 +373,12 @@ static int guess_to_remote(const char *address, struct node_id *node_id,
}

static int dumponchaindescriptors(const char *hsm_secret_path, const char *passwd,
const bool private)
const bool private, const bool testnet)
{
struct secret hsm_secret;
u8 bip32_seed[BIP32_ENTROPY_LEN_256];
u32 salt = 0;
u32 version = testnet ? BIP32_VER_TEST_PRIVATE : BIP32_VER_MAIN_PRIVATE;
struct ext_key master_extkey;
char *enc_xpub, *descriptor, checksum[DESCRIPTOR_CHECKSUM_LENGTH + 1];

Expand All @@ -397,9 +398,7 @@ static int dumponchaindescriptors(const char *hsm_secret_path, const char *passw
salt++;
/* ..Which is used to derive m/ */
} while (bip32_key_from_seed(bip32_seed, sizeof(bip32_seed),
/* An xpub can easily be converted to a tpub */
BIP32_VER_MAIN_PRIVATE,
0, &master_extkey) != WALLY_OK);
version, 0, &master_extkey) != WALLY_OK);

if (bip32_key_to_base58(&master_extkey, BIP32_FLAG_KEY_PUBLIC, &enc_xpub) != WALLY_OK)
errx(ERROR_LIBWALLY, "Can't encode xpub");
Expand Down Expand Up @@ -492,7 +491,8 @@ int main(int argc, char *argv[])

return dumponchaindescriptors(argv[2],
argc > 3 && !streq(argv[3], "") ? argv[3] : NULL,
argc > 4 && streq(argv[4], "private"));
argc > 4 && streq(argv[4], "private"),
argc > 5 && streq(argv[5], "testnet"));
}

show_usage(argv[0]);
Expand Down

0 comments on commit 3710c5e

Please sign in to comment.