@@ -84,6 +84,7 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
84
84
85
85
case WIRE_HSMD_GET_PER_COMMITMENT_POINT :
86
86
case WIRE_HSMD_CHECK_FUTURE_SECRET :
87
+ case WIRE_HSMD_READY_CHANNEL :
87
88
return (client -> capabilities & HSM_CAP_COMMITMENT_POINT ) != 0 ;
88
89
89
90
case WIRE_HSMD_SIGN_REMOTE_COMMITMENT_TX :
@@ -94,6 +95,7 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
94
95
return (client -> capabilities & HSM_CAP_SIGN_CLOSING_TX ) != 0 ;
95
96
96
97
case WIRE_HSMD_INIT :
98
+ case WIRE_HSMD_NEW_CHANNEL :
97
99
case WIRE_HSMD_CLIENT_HSMFD :
98
100
case WIRE_HSMD_SIGN_WITHDRAWAL :
99
101
case WIRE_HSMD_SIGN_INVOICE :
@@ -112,6 +114,8 @@ bool hsmd_check_client_capabilities(struct hsmd_client *client,
112
114
case WIRE_HSMD_CANNOUNCEMENT_SIG_REPLY :
113
115
case WIRE_HSMD_CUPDATE_SIG_REPLY :
114
116
case WIRE_HSMD_CLIENT_HSMFD_REPLY :
117
+ case WIRE_HSMD_NEW_CHANNEL_REPLY :
118
+ case WIRE_HSMD_READY_CHANNEL_REPLY :
115
119
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY :
116
120
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY :
117
121
case WIRE_HSMD_SIGN_INVOICE_REPLY :
@@ -266,6 +270,70 @@ static void get_channel_seed(const struct node_id *peer_id, u64 dbid,
266
270
info , strlen (info ));
267
271
}
268
272
273
+ /*~ This is used to declare a new channel. */
274
+ static u8 * handle_new_channel (struct hsmd_client * c , const u8 * msg_in )
275
+ {
276
+ struct node_id peer_id ;
277
+ u64 dbid ;
278
+
279
+ if (!fromwire_hsmd_new_channel (msg_in , & peer_id , & dbid ))
280
+ return hsmd_status_malformed_request (c , msg_in );
281
+
282
+ return towire_hsmd_new_channel_reply (NULL );
283
+ }
284
+
285
+ static bool mem_is_zero (const void * mem , size_t len )
286
+ {
287
+ size_t i ;
288
+ for (i = 0 ; i < len ; ++ i )
289
+ if (((const unsigned char * )mem )[i ])
290
+ return false;
291
+ return true;
292
+ }
293
+
294
+ /*~ This is used to provide all unchanging public channel parameters. */
295
+ static u8 * handle_ready_channel (struct hsmd_client * c , const u8 * msg_in )
296
+ {
297
+ bool is_outbound ;
298
+ struct amount_sat channel_value ;
299
+ struct amount_msat push_value ;
300
+ struct bitcoin_txid funding_txid ;
301
+ u16 funding_txout ;
302
+ u16 local_to_self_delay ;
303
+ u8 * local_shutdown_script ;
304
+ struct basepoints remote_basepoints ;
305
+ struct pubkey remote_funding_pubkey ;
306
+ u16 remote_to_self_delay ;
307
+ u8 * remote_shutdown_script ;
308
+ bool option_static_remotekey ;
309
+ bool option_anchor_outputs ;
310
+ struct amount_msat value_msat ;
311
+
312
+ if (!fromwire_hsmd_ready_channel (tmpctx , msg_in , & is_outbound ,
313
+ & channel_value , & push_value , & funding_txid ,
314
+ & funding_txout , & local_to_self_delay ,
315
+ & local_shutdown_script ,
316
+ & remote_basepoints ,
317
+ & remote_funding_pubkey ,
318
+ & remote_to_self_delay ,
319
+ & remote_shutdown_script ,
320
+ & option_static_remotekey ,
321
+ & option_anchor_outputs ))
322
+ return hsmd_status_malformed_request (c , msg_in );
323
+
324
+ /* Fail fast if any values are obviously uninitialized. */
325
+ assert (amount_sat_greater (channel_value , AMOUNT_SAT (0 )));
326
+ assert (amount_sat_to_msat (& value_msat , channel_value ));
327
+ assert (amount_msat_less_eq (push_value , value_msat ));
328
+ assert (!mem_is_zero (& funding_txid , sizeof (funding_txid )));
329
+ assert (local_to_self_delay > 0 );
330
+ assert (!mem_is_zero (& remote_basepoints , sizeof (remote_basepoints )));
331
+ assert (!mem_is_zero (& remote_funding_pubkey , sizeof (remote_funding_pubkey )));
332
+ assert (remote_to_self_delay > 0 );
333
+
334
+ return towire_hsmd_ready_channel_reply (NULL );
335
+ }
336
+
269
337
/*~ For almost every wallet tx we use the BIP32 seed, but not for onchain
270
338
* unilateral closes from a peer: they (may) have an output to us using a
271
339
* public key based on the channel basepoints. It's a bit spammy to spend
@@ -1080,12 +1148,15 @@ static u8 *handle_sign_remote_commitment_tx(struct hsmd_client *c, const u8 *msg
1080
1148
const u8 * funding_wscript ;
1081
1149
struct pubkey remote_per_commit ;
1082
1150
bool option_static_remotekey ;
1151
+ struct sha256 * htlc_rhash ;
1152
+ u64 commit_num ;
1083
1153
1084
1154
if (!fromwire_hsmd_sign_remote_commitment_tx (tmpctx , msg_in ,
1085
1155
& tx ,
1086
1156
& remote_funding_pubkey ,
1087
1157
& remote_per_commit ,
1088
- & option_static_remotekey ))
1158
+ & option_static_remotekey ,
1159
+ & htlc_rhash , & commit_num ))
1089
1160
return hsmd_status_malformed_request (c , msg_in );
1090
1161
tx -> chainparams = c -> chainparams ;
1091
1162
@@ -1170,13 +1241,16 @@ static u8 *handle_sign_commitment_tx(struct hsmd_client *c, const u8 *msg_in)
1170
1241
struct secret channel_seed ;
1171
1242
struct bitcoin_tx * tx ;
1172
1243
struct bitcoin_signature sig ;
1244
+ struct sha256 * rhashes ;
1245
+ u64 commit_num ;
1173
1246
struct secrets secrets ;
1174
1247
const u8 * funding_wscript ;
1175
1248
1176
1249
if (!fromwire_hsmd_sign_commitment_tx (tmpctx , msg_in ,
1177
1250
& peer_id , & dbid ,
1178
1251
& tx ,
1179
- & remote_funding_pubkey ))
1252
+ & remote_funding_pubkey ,
1253
+ & rhashes , & commit_num ))
1180
1254
return hsmd_status_malformed_request (c , msg_in );
1181
1255
1182
1256
tx -> chainparams = c -> chainparams ;
@@ -1344,6 +1418,10 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
1344
1418
"libhsmd" ,
1345
1419
hsmd_wire_name (t ));
1346
1420
1421
+ case WIRE_HSMD_NEW_CHANNEL :
1422
+ return handle_new_channel (client , msg );
1423
+ case WIRE_HSMD_READY_CHANNEL :
1424
+ return handle_ready_channel (client , msg );
1347
1425
case WIRE_HSMD_GET_OUTPUT_SCRIPTPUBKEY :
1348
1426
return handle_get_output_scriptpubkey (client , msg );
1349
1427
case WIRE_HSMD_CHECK_FUTURE_SECRET :
@@ -1390,6 +1468,8 @@ u8 *hsmd_handle_client_message(const tal_t *ctx, struct hsmd_client *client,
1390
1468
case WIRE_HSMD_CANNOUNCEMENT_SIG_REPLY :
1391
1469
case WIRE_HSMD_CUPDATE_SIG_REPLY :
1392
1470
case WIRE_HSMD_CLIENT_HSMFD_REPLY :
1471
+ case WIRE_HSMD_NEW_CHANNEL_REPLY :
1472
+ case WIRE_HSMD_READY_CHANNEL_REPLY :
1393
1473
case WIRE_HSMD_NODE_ANNOUNCEMENT_SIG_REPLY :
1394
1474
case WIRE_HSMD_SIGN_WITHDRAWAL_REPLY :
1395
1475
case WIRE_HSMD_SIGN_INVOICE_REPLY :
0 commit comments