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