| 53 | } |
| 54 | |
| 55 | static void hsm_sign_b12(struct lightningd *ld, |
| 56 | const char *messagename, |
| 57 | const char *fieldname, |
| 58 | const struct sha256 *merkle, |
| 59 | const u8 *publictweak, |
| 60 | const struct point32 *key, |
| 61 | struct bip340sig *sig) |
| 62 | { |
| 63 | u8 *msg; |
| 64 | struct sha256 sighash; |
| 65 | |
| 66 | msg = towire_hsmd_sign_bolt12(NULL, messagename, fieldname, merkle, |
| 67 | publictweak); |
| 68 | if (!wire_sync_write(ld->hsm_fd, take(msg))) |
| 69 | fatal("Could not write to HSM: %s", strerror(errno)); |
| 70 | |
| 71 | msg = wire_sync_read(tmpctx, ld->hsm_fd); |
| 72 | if (!fromwire_hsmd_sign_bolt12_reply(msg, sig)) |
| 73 | fatal("HSM gave bad sign_offer_reply %s", |
| 74 | tal_hex(msg, msg)); |
| 75 | |
| 76 | /* Now we sanity-check! */ |
| 77 | sighash_from_merkle(messagename, fieldname, merkle, &sighash); |
| 78 | if (secp256k1_schnorrsig_verify(secp256k1_ctx, sig->u8, |
| 79 | sighash.u.u8, sizeof(sighash.u.u8), &key->pubkey) != 1) |
| 80 | fatal("HSM gave bad signature %s for pubkey %s", |
| 81 | type_to_string(tmpctx, struct bip340sig, sig), |
| 82 | type_to_string(tmpctx, struct point32, key)); |
| 83 | } |
| 84 | |
| 85 | static struct command_result *json_createoffer(struct command *cmd, |
| 86 | const char *buffer, |
no test coverage detected