|
3 | 3 | #include <common/channel_config.h> |
4 | 4 | #include <common/features.h> |
5 | 5 | #include <common/initial_commit_tx.h> |
| 6 | +#include <common/status.h> |
6 | 7 | #include <common/type_to_string.h> |
| 8 | +#include <hsmd/hsmd_wiregen.h> |
7 | 9 | #include <openingd/common.h> |
| 10 | +#include <wire/wire_sync.h> |
| 11 | + |
| 12 | +#define HSM_FD 6 |
8 | 13 |
|
9 | 14 | /*~ This is the key function that checks that their configuration is reasonable: |
10 | 15 | * it applied for both the case where they're trying to open a channel, and when |
@@ -225,3 +230,32 @@ u8 *no_upfront_shutdown_script(const tal_t *ctx, |
225 | 230 |
|
226 | 231 | return NULL; |
227 | 232 | } |
| 233 | + |
| 234 | +void validate_initial_commitment_signature(struct bitcoin_tx *tx, |
| 235 | + struct bitcoin_signature *sig) |
| 236 | +{ |
| 237 | + // Validate the counterparty's signature. |
| 238 | + struct existing_htlc **htlcs = tal_arr(NULL, struct existing_htlc *, 0); |
| 239 | + struct bitcoin_signature *htlc_sigs = tal_arr(NULL, struct bitcoin_signature, 0); |
| 240 | + u32 feerate = 0; // unused since there are no htlcs |
| 241 | + u64 commit_num = 0; |
| 242 | + const u8 * msg = |
| 243 | + towire_hsmd_validate_commitment_tx(NULL, |
| 244 | + tx, |
| 245 | + (const struct simple_htlc **) htlcs, |
| 246 | + commit_num, |
| 247 | + feerate, |
| 248 | + sig, |
| 249 | + htlc_sigs); |
| 250 | + tal_free(htlc_sigs); |
| 251 | + tal_free(htlcs); |
| 252 | + wire_sync_write(HSM_FD, take(msg)); |
| 253 | + msg = wire_sync_read(tmpctx, HSM_FD); |
| 254 | + struct secret *old_secret; |
| 255 | + struct pubkey next_point; |
| 256 | + if (!fromwire_hsmd_validate_commitment_tx_reply(tmpctx, msg, &old_secret, &next_point)) |
| 257 | + status_failed(STATUS_FAIL_HSM_IO, |
| 258 | + "Reading validate_commitment_tx reply: %s", |
| 259 | + tal_hex(tmpctx, msg)); |
| 260 | +} |
| 261 | + |
0 commit comments