~ This is used by channeld to create signatures for the remote peer's * commitment transaction. It's functionally identical to signing our own, * but we expect to do this repeatedly as commitment transactions are * updated. * * The HSM almost certainly *should* do more checks before signing! */ FIXME: make sure it meets some criteria? */
| 1641 | */ |
| 1642 | /* FIXME: make sure it meets some criteria? */ |
| 1643 | static u8 *handle_sign_remote_commitment_tx(struct hsmd_client *c, const u8 *msg_in) |
| 1644 | { |
| 1645 | struct pubkey remote_funding_pubkey, local_funding_pubkey; |
| 1646 | struct secret channel_seed; |
| 1647 | struct bitcoin_tx *tx; |
| 1648 | struct bitcoin_signature sig; |
| 1649 | struct secrets secrets; |
| 1650 | const u8 *funding_wscript; |
| 1651 | struct pubkey remote_per_commit; |
| 1652 | bool option_static_remotekey; |
| 1653 | u64 commit_num; |
| 1654 | struct hsm_htlc *htlc; |
| 1655 | u32 feerate; |
| 1656 | |
| 1657 | if (!fromwire_hsmd_sign_remote_commitment_tx(tmpctx, msg_in, |
| 1658 | &tx, |
| 1659 | &remote_funding_pubkey, |
| 1660 | &remote_per_commit, |
| 1661 | &option_static_remotekey, |
| 1662 | &commit_num, |
| 1663 | &htlc, &feerate)) |
| 1664 | return hsmd_status_malformed_request(c, msg_in); |
| 1665 | tx->chainparams = c->chainparams; |
| 1666 | |
| 1667 | /* Basic sanity checks. */ |
| 1668 | if (tx->wtx->num_inputs != 1) |
| 1669 | return hsmd_status_bad_request_fmt(c, msg_in, |
| 1670 | "tx must have 1 input"); |
| 1671 | |
| 1672 | if (tx->wtx->num_outputs == 0) |
| 1673 | return hsmd_status_bad_request_fmt(c, msg_in, |
| 1674 | "tx must have > 0 outputs"); |
| 1675 | |
| 1676 | get_channel_seed(&c->id, c->dbid, &channel_seed); |
| 1677 | derive_basepoints(&channel_seed, |
| 1678 | &local_funding_pubkey, NULL, &secrets, NULL); |
| 1679 | |
| 1680 | funding_wscript = bitcoin_redeem_2of2(tmpctx, |
| 1681 | &local_funding_pubkey, |
| 1682 | &remote_funding_pubkey); |
| 1683 | sign_tx_input(tx, 0, NULL, funding_wscript, |
| 1684 | &secrets.funding_privkey, |
| 1685 | &local_funding_pubkey, |
| 1686 | SIGHASH_ALL, |
| 1687 | &sig); |
| 1688 | check_overgrind(&sig); |
| 1689 | |
| 1690 | return towire_hsmd_sign_tx_reply(NULL, &sig); |
| 1691 | } |
| 1692 | |
| 1693 | /*~ This is used when the remote peer's commitment transaction is revoked; |
| 1694 | * we can use the revocation secret to spend the outputs. For simplicity, |
no test coverage detected