~ This is another lightningd-only interface; signing a commit transaction. * This is dangerous, since if we sign a revoked commitment tx we'll lose * funds, thus it's only available to lightningd. * * * Oh look, another FIXME! */ FIXME: Ensure HSM never does this twice for same dbid! */
| 1846 | * Oh look, another FIXME! */ |
| 1847 | /* FIXME: Ensure HSM never does this twice for same dbid! */ |
| 1848 | static u8 *handle_sign_commitment_tx(struct hsmd_client *c, const u8 *msg_in) |
| 1849 | { |
| 1850 | struct pubkey remote_funding_pubkey, local_funding_pubkey; |
| 1851 | struct node_id peer_id; |
| 1852 | u64 dbid; |
| 1853 | struct secret channel_seed; |
| 1854 | struct bitcoin_tx *tx; |
| 1855 | struct bitcoin_signature sig; |
| 1856 | u64 commit_num; |
| 1857 | struct secrets secrets; |
| 1858 | const u8 *funding_wscript; |
| 1859 | |
| 1860 | if (!fromwire_hsmd_sign_commitment_tx(tmpctx, msg_in, |
| 1861 | &peer_id, &dbid, |
| 1862 | &tx, |
| 1863 | &remote_funding_pubkey, |
| 1864 | &commit_num)) |
| 1865 | return hsmd_status_malformed_request(c, msg_in); |
| 1866 | |
| 1867 | tx->chainparams = c->chainparams; |
| 1868 | |
| 1869 | /* Basic sanity checks. */ |
| 1870 | if (tx->wtx->num_inputs != 1) |
| 1871 | return hsmd_status_bad_request(c, msg_in, |
| 1872 | "tx must have 1 input"); |
| 1873 | |
| 1874 | if (tx->wtx->num_outputs == 0) |
| 1875 | return hsmd_status_bad_request_fmt(c, msg_in, |
| 1876 | "tx must have > 0 outputs"); |
| 1877 | |
| 1878 | get_channel_seed(&peer_id, dbid, &channel_seed); |
| 1879 | derive_basepoints(&channel_seed, |
| 1880 | &local_funding_pubkey, NULL, &secrets, NULL); |
| 1881 | |
| 1882 | /*~ Bitcoin signatures cover the (part of) the script they're |
| 1883 | * executing; the rules are a bit complex in general, but for |
| 1884 | * Segregated Witness it's simply the current script. */ |
| 1885 | funding_wscript = bitcoin_redeem_2of2(tmpctx, |
| 1886 | &local_funding_pubkey, |
| 1887 | &remote_funding_pubkey); |
| 1888 | sign_tx_input(tx, 0, NULL, funding_wscript, |
| 1889 | &secrets.funding_privkey, |
| 1890 | &local_funding_pubkey, |
| 1891 | SIGHASH_ALL, |
| 1892 | &sig); |
| 1893 | check_overgrind(&sig); |
| 1894 | |
| 1895 | return towire_hsmd_sign_commitment_tx_reply(NULL, &sig); |
| 1896 | } |
| 1897 | |
| 1898 | /* ~This stub implementation is overriden by fully validating signers |
| 1899 | * that need to independently verify the peer's signatures. */ |
no test coverage detected