script: Use pkh to construct p2pkh output scripts

So far we always needed to know the public key, which was not the case
for addresses that we don't own. Moving the hashing outside of the
script construction allows us to send to arbitrary addresses. I also
added the hash computation to the pubkey primitives.
This commit is contained in:
Christian Decker
2017-06-14 10:29:10 +02:00
committed by Rusty Russell
parent f10b779c83
commit 40165ba6d5
5 changed files with 24 additions and 6 deletions

View File

@@ -99,3 +99,13 @@ static char *privkey_to_hexstr(const tal_t *ctx, const struct privkey *secret)
}
REGISTER_TYPE_TO_STRING(privkey, privkey_to_hexstr);
REGISTER_TYPE_TO_HEXSTR(secret);
void pubkey_to_hash160(const struct pubkey *pk, struct ripemd160 *hash)
{
u8 der[PUBKEY_DER_LEN];
struct sha256 h;
pubkey_to_der(der, pk);
sha256(&h, der, sizeof(der));
ripemd160(hash, h.u.u8, sizeof(h));
}