From 82f5b3ad51eec853ded3eca6c2a5b30cdc44777e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 21 Feb 2017 15:15:29 +1030 Subject: [PATCH] bitcoin/script: bitcoin_witness_p2wpkh() For the wallet code to use for change. Signed-off-by: Rusty Russell --- bitcoin/script.c | 15 +++++++++++++++ bitcoin/script.h | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/bitcoin/script.c b/bitcoin/script.c index ae2c5b732..8e354e5a0 100644 --- a/bitcoin/script.c +++ b/bitcoin/script.c @@ -281,6 +281,21 @@ void bitcoin_witness_p2sh_p2wpkh(const tal_t *ctx, input->witness[1] = stack_key(input->witness, key); } +u8 **bitcoin_witness_p2wpkh(const tal_t *ctx, + const secp256k1_ecdsa_signature *sig, + const struct pubkey *key) +{ + u8 **witness; + + /* BIP141: The witness must consist of exactly 2 items (≤ 520 + * bytes each). The first one a signature, and the second one + * a public key. */ + witness = tal_arr(ctx, u8 *, 2); + witness[0] = stack_sig(witness, sig); + witness[1] = stack_key(witness, key); + return witness; +} + /* Create an output script for a 32-byte witness. */ u8 *scriptpubkey_p2wsh(const tal_t *ctx, const u8 *witnessscript) { diff --git a/bitcoin/script.h b/bitcoin/script.h index 5dafe5098..49c32846b 100644 --- a/bitcoin/script.h +++ b/bitcoin/script.h @@ -85,6 +85,11 @@ u8 **bitcoin_witness_2of2(const tal_t *ctx, const struct pubkey *key1, const struct pubkey *key2); +/* Create a witness which spends a p2wpkh. */ +u8 **bitcoin_witness_p2wpkh(const tal_t *ctx, + const secp256k1_ecdsa_signature *sig, + const struct pubkey *key); + /* Create a witness which spends a "secret_or_delay" scriptpubkey */ u8 **bitcoin_witness_secret(const tal_t *ctx, const void *secret, size_t secret_len,