From 2e36affb77fe375c3542a44f5b9a1a654ade3afb Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 24 Jul 2015 16:00:11 +0930 Subject: [PATCH] test-cli/get-revocation-secret: new helper. Give the revocation secret (or hash) for a given index number. Signed-off-by: Rusty Russell --- Makefile | 2 +- test-cli/get-revocation-secret.c | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test-cli/get-revocation-secret.c diff --git a/Makefile b/Makefile index 946712525..59cbbccfc 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ FEATURES := -DHAS_CSV=1 -DALPHA_TXSTYLE=1 -DUSE_SCHNORR=1 # Bitcoin uses DER for signatures #FEATURES := -DSCRIPTS_USE_DER -PROGRAMS := test-cli/open-channel test-cli/open-commit-sig test-cli/check-commit-sig test-cli/get-anchor-depth test-cli/create-steal-tx test-cli/create-commit-spend-tx test-cli/close-channel test-cli/create-close-tx test-cli/update-channel test-cli/update-channel-accept test-cli/update-channel-signature test-cli/update-channel-complete test-cli/create-commit-tx test-cli/txid-of test-cli/create-anchor-tx test-cli/open-anchor-id test-cli/open-complete test-cli/check-open-complete test-cli/open-escape-sigs test-cli/create-escape-tx +PROGRAMS := test-cli/open-channel test-cli/open-commit-sig test-cli/check-commit-sig test-cli/get-anchor-depth test-cli/create-steal-tx test-cli/create-commit-spend-tx test-cli/close-channel test-cli/create-close-tx test-cli/update-channel test-cli/update-channel-accept test-cli/update-channel-signature test-cli/update-channel-complete test-cli/create-commit-tx test-cli/txid-of test-cli/create-anchor-tx test-cli/open-anchor-id test-cli/open-complete test-cli/check-open-complete test-cli/open-escape-sigs test-cli/create-escape-tx test-cli/get-revocation-secret BITCOIN_OBJS := bitcoin/address.o bitcoin/base58.o bitcoin/pubkey.o bitcoin/script.o bitcoin/shadouble.o bitcoin/signature.o bitcoin/tx.o diff --git a/test-cli/get-revocation-secret.c b/test-cli/get-revocation-secret.c new file mode 100644 index 000000000..b5cf5fc23 --- /dev/null +++ b/test-cli/get-revocation-secret.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + struct sha256 seed, secret; + bool do_hash = false; + char hexstr[hex_str_size(sizeof(secret))]; + + err_set_progname(argv[0]); + + opt_register_noarg("--help|-h", opt_usage_and_exit, + " \n" + "A test program to output secret or hash to stdout.", + "Print this message."); + opt_register_noarg("--hash", opt_set_bool, &do_hash, + "Output hash instead of secret itself"); + + opt_parse(&argc, argv, opt_log_stderr_exit); + + if (argc != 3) + opt_usage_exit_fail("Expected 2 arguments"); + + if (!hex_decode(argv[1], strlen(argv[1]), &seed, sizeof(seed))) + errx(1, "Invalid seed '%s' - need 256 hex bits", argv[1]); + + /* Get the given revoction secret. */ + shachain_from_seed(&seed, atoi(argv[2]), &secret); + if (do_hash) + sha256(&secret, secret.u.u8, sizeof(secret.u.u8)); + + if (!hex_encode(&secret, sizeof(secret), hexstr, sizeof(hexstr))) + abort(); + + if (!write_all(STDOUT_FILENO, hexstr, strlen(hexstr))) + err(1, "Writing out hexstr"); + + return 0; +}