|
|
@ -683,6 +683,55 @@ fail: |
|
|
|
return io_close(conn); |
|
|
|
} |
|
|
|
|
|
|
|
static struct io_plan *handle_sign_mutual_close_tx(struct io_conn *conn, |
|
|
|
struct client *c) |
|
|
|
{ |
|
|
|
struct daemon_conn *dc = &c->dc; |
|
|
|
struct secret channel_seed; |
|
|
|
struct bitcoin_tx *tx; |
|
|
|
struct pubkey remote_funding_pubkey, local_funding_pubkey; |
|
|
|
secp256k1_ecdsa_signature sig; |
|
|
|
struct secrets secrets; |
|
|
|
u64 funding_amount; |
|
|
|
const u8 *funding_wscript; |
|
|
|
|
|
|
|
if (!fromwire_hsm_sign_mutual_close_tx(tmpctx, dc->msg_in, |
|
|
|
&tx, |
|
|
|
&remote_funding_pubkey, |
|
|
|
&funding_amount)) { |
|
|
|
status_broken("bad hsm_sign_htlc_mutual_close_tx for client %s", |
|
|
|
type_to_string(tmpctx, struct pubkey, &c->id)); |
|
|
|
goto fail; |
|
|
|
} |
|
|
|
|
|
|
|
/* FIXME: We should know dust level, decent fee range and
|
|
|
|
* balances, and final_keyindex, and thus be able to check tx |
|
|
|
* outputs! */ |
|
|
|
get_channel_seed(&c->id, c->dbid, &channel_seed); |
|
|
|
derive_basepoints(&channel_seed, |
|
|
|
&local_funding_pubkey, NULL, &secrets, NULL); |
|
|
|
|
|
|
|
funding_wscript = bitcoin_redeem_2of2(tmpctx, |
|
|
|
&local_funding_pubkey, |
|
|
|
&remote_funding_pubkey); |
|
|
|
/* Need input amount for signing */ |
|
|
|
tx->input[0].amount = tal_dup(tx->input, u64, &funding_amount); |
|
|
|
sign_tx_input(tx, 0, NULL, funding_wscript, |
|
|
|
&secrets.funding_privkey, |
|
|
|
&local_funding_pubkey, |
|
|
|
&sig); |
|
|
|
|
|
|
|
daemon_conn_send(dc, take(towire_hsm_sign_tx_reply(NULL, &sig))); |
|
|
|
return daemon_conn_read_next(conn, dc); |
|
|
|
|
|
|
|
fail: |
|
|
|
daemon_conn_send(c->master, |
|
|
|
take(towire_hsmstatus_client_bad_request(NULL, |
|
|
|
&c->id, |
|
|
|
dc->msg_in))); |
|
|
|
return io_close(conn); |
|
|
|
} |
|
|
|
|
|
|
|
static bool check_client_capabilities(struct client *client, |
|
|
|
enum hsm_client_wire_type t) |
|
|
|
{ |
|
|
@ -708,6 +757,9 @@ static bool check_client_capabilities(struct client *client, |
|
|
|
case WIRE_HSM_SIGN_REMOTE_HTLC_TX: |
|
|
|
return (client->capabilities & HSM_CAP_SIGN_REMOTE_TX) != 0; |
|
|
|
|
|
|
|
case WIRE_HSM_SIGN_MUTUAL_CLOSE_TX: |
|
|
|
return (client->capabilities & HSM_CAP_SIGN_CLOSING_TX) != 0; |
|
|
|
|
|
|
|
case WIRE_HSM_INIT: |
|
|
|
case WIRE_HSM_CLIENT_HSMFD: |
|
|
|
case WIRE_HSM_SIGN_FUNDING: |
|
|
@ -812,6 +864,9 @@ static struct io_plan *handle_client(struct io_conn *conn, |
|
|
|
case WIRE_HSM_SIGN_REMOTE_HTLC_TX: |
|
|
|
return handle_sign_remote_htlc_tx(conn, c); |
|
|
|
|
|
|
|
case WIRE_HSM_SIGN_MUTUAL_CLOSE_TX: |
|
|
|
return handle_sign_mutual_close_tx(conn, c); |
|
|
|
|
|
|
|
case WIRE_HSM_ECDH_RESP: |
|
|
|
case WIRE_HSM_CANNOUNCEMENT_SIG_REPLY: |
|
|
|
case WIRE_HSM_CUPDATE_SIG_REPLY: |
|
|
|