/* Only does SIGHASH_ALL */ void sign_tx_input(secp256k1_context *secpctx, struct bitcoin_tx *tx, unsigned int in, const u8 *subscript, size_t subscript_len, const struct privkey *privkey, const struct pubkey *key, struct signature *sig) { struct sha256_double hash; sha256_tx_one_input(tx, in, subscript, subscript_len, &hash); dump_tx("Signing", tx, in, subscript, subscript_len, key, &hash); sign_hash(secpctx, privkey, &hash, sig); }
void queue_pkt_open_commit_sig(struct peer *peer) { OpenCommitSig *s = tal(peer, OpenCommitSig); open_commit_sig__init(s); dump_tx("Creating sig for:", peer->them.commit->tx); dump_key("Using key:", &peer->us.commitkey); peer->them.commit->sig = tal(peer->them.commit, struct bitcoin_signature); peer->them.commit->sig->stype = SIGHASH_ALL; peer_sign_theircommit(peer, peer->them.commit->tx, &peer->them.commit->sig->sig); s->sig = signature_to_proto(s, &peer->them.commit->sig->sig); queue_pkt(peer, PKT__PKT_OPEN_COMMIT_SIG, s); }
bool check_tx_sig(secp256k1_context *secpctx, struct bitcoin_tx *tx, size_t input_num, const u8 *redeemscript, size_t redeemscript_len, const struct pubkey *key, const struct bitcoin_signature *sig) { struct sha256_double hash; bool ret; assert(input_num < tx->input_count); sha256_tx_one_input(tx, input_num, redeemscript, redeemscript_len, &hash); /* We only use SIGHASH_ALL for the moment. */ if (sig->stype != SIGHASH_ALL) return false; ret = check_signed_hash(secpctx, &hash, &sig->sig, key); if (!ret) dump_tx("Sig failed", tx, input_num, redeemscript, redeemscript_len, key, &hash); return ret; }