mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
test-cli/get-revocation-secret: new helper.
Give the revocation secret (or hash) for a given index number. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
2
Makefile
2
Makefile
@@ -8,7 +8,7 @@ FEATURES := -DHAS_CSV=1 -DALPHA_TXSTYLE=1 -DUSE_SCHNORR=1
|
|||||||
# Bitcoin uses DER for signatures
|
# Bitcoin uses DER for signatures
|
||||||
#FEATURES := -DSCRIPTS_USE_DER
|
#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
|
BITCOIN_OBJS := bitcoin/address.o bitcoin/base58.o bitcoin/pubkey.o bitcoin/script.o bitcoin/shadouble.o bitcoin/signature.o bitcoin/tx.o
|
||||||
|
|
||||||
|
|||||||
45
test-cli/get-revocation-secret.c
Normal file
45
test-cli/get-revocation-secret.c
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include <ccan/crypto/shachain/shachain.h>
|
||||||
|
#include <ccan/short_types/short_types.h>
|
||||||
|
#include <ccan/tal/tal.h>
|
||||||
|
#include <ccan/opt/opt.h>
|
||||||
|
#include <ccan/str/hex/hex.h>
|
||||||
|
#include <ccan/err/err.h>
|
||||||
|
#include <ccan/read_write_all/read_write_all.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
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,
|
||||||
|
"<seed> <index>\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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user