mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
bitcoin/script: helper to create ScriptCode for signing P2WPKH.
sign_tx_input() now takes a witness_script arg: P2WPKH doesn't really have a witness_script, but for signing it behaves as if it does. This helper constructs that "fake" witness_script. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
df5d4e3c10
commit
af080d5613
2 changed files with 29 additions and 0 deletions
|
@ -282,6 +282,32 @@ u8 *scriptsig_pay_to_pubkeyhash(const tal_t *ctx,
|
|||
return script;
|
||||
}
|
||||
|
||||
/* Create scriptcode (fake witness, basically) for P2WPKH */
|
||||
u8 *p2wpkh_scriptcode(const tal_t *ctx, const struct pubkey *key)
|
||||
{
|
||||
struct sha256 h;
|
||||
struct ripemd160 pkhash;
|
||||
u8 *script = tal_arr(ctx, u8, 0);
|
||||
|
||||
sha256(&h, key->der, sizeof(key->der));
|
||||
ripemd160(&pkhash, h.u.u8, sizeof(h));
|
||||
/* BIP143:
|
||||
*
|
||||
* For P2WPKH witness program, the scriptCode is
|
||||
* 0x1976a914{20-byte-pubkey-hash}88ac.
|
||||
*/
|
||||
|
||||
/* PUSH(25): OP_DUP OP_HASH160 PUSH(20) 20-byte-pubkey-hash
|
||||
* OP_EQUALVERIFY OP_CHECKSIG */
|
||||
add_op(&script, OP_DUP);
|
||||
add_op(&script, OP_HASH160);
|
||||
add_push_bytes(&script, &pkhash, sizeof(pkhash));
|
||||
add_op(&script, OP_EQUALVERIFY);
|
||||
add_op(&script, OP_CHECKSIG);
|
||||
|
||||
return script;
|
||||
}
|
||||
|
||||
/* Assumes redeemscript contains CHECKSIG, not CHECKMULTISIG */
|
||||
u8 *scriptsig_p2sh_single_sig(const tal_t *ctx,
|
||||
const u8 *redeem_script,
|
||||
|
|
|
@ -41,6 +41,9 @@ u8 *scriptsig_pay_to_pubkeyhash(const tal_t *ctx,
|
|||
const struct pubkey *key,
|
||||
const struct bitcoin_signature *sig);
|
||||
|
||||
/* Create scriptcode (fake witness, basically) for P2WPKH */
|
||||
u8 *p2wpkh_scriptcode(const tal_t *ctx, const struct pubkey *key);
|
||||
|
||||
u8 *scriptpubkey_htlc_send(const tal_t *ctx,
|
||||
const struct pubkey *ourkey,
|
||||
const struct pubkey *theirkey,
|
||||
|
|
Loading…
Add table
Reference in a new issue