| 159 | } |
| 160 | |
| 161 | void sign_tx_input(const struct bitcoin_tx *tx, |
| 162 | unsigned int in, |
| 163 | const u8 *subscript, |
| 164 | const u8 *witness_script, |
| 165 | const struct privkey *privkey, const struct pubkey *key, |
| 166 | enum sighash_type sighash_type, |
| 167 | struct bitcoin_signature *sig) |
| 168 | { |
| 169 | struct sha256_double hash; |
| 170 | bool use_segwit = witness_script != NULL; |
| 171 | const u8 *script = use_segwit ? witness_script : subscript; |
| 172 | |
| 173 | assert(sighash_type_valid(sighash_type)); |
| 174 | |
| 175 | sig->sighash_type = sighash_type; |
| 176 | bitcoin_tx_hash_for_sig(tx, in, script, sighash_type, &hash); |
| 177 | |
| 178 | dump_tx("Signing", tx, in, subscript, key, &hash); |
| 179 | sign_hash(privkey, &hash, &sig->s); |
| 180 | } |
| 181 | |
| 182 | bool check_signed_hash(const struct sha256_double *hash, |
| 183 | const secp256k1_ecdsa_signature *signature, |