| 63 | } |
| 64 | |
| 65 | static void hsm_sign_b12(struct lightningd *ld, |
| 66 | const char *messagename, |
| 67 | const char *fieldname, |
| 68 | const struct sha256 *merkle, |
| 69 | const u8 *publictweak, |
| 70 | const struct pubkey *key, |
| 71 | struct bip340sig *sig) |
| 72 | { |
| 73 | const u8 *msg; |
| 74 | struct sha256 sighash; |
| 75 | /* Needs to be a (non-nul-terminated) tal_arr */ |
| 76 | const u8 *info = tal_dup_arr(tmpctx, u8, |
| 77 | (const u8 *)NODE_ALIAS_BASE_STRING, |
| 78 | strlen(NODE_ALIAS_BASE_STRING), 0); |
| 79 | |
| 80 | msg = towire_hsmd_sign_bolt12_2(NULL, messagename, fieldname, merkle, |
| 81 | info, publictweak); |
| 82 | msg = hsm_sync_req(tmpctx, ld, take(msg)); |
| 83 | if (!fromwire_hsmd_sign_bolt12_2_reply(msg, sig)) |
| 84 | fatal("HSM gave bad sign_bolt12_2 %s", |
| 85 | tal_hex(msg, msg)); |
| 86 | |
| 87 | /* Now we sanity-check! */ |
| 88 | sighash_from_merkle(messagename, fieldname, merkle, &sighash); |
| 89 | if (!check_schnorr_sig(&sighash, &key->pubkey, sig)) |
| 90 | fatal("HSM gave bad signature %s for pubkey %s", |
| 91 | fmt_bip340sig(tmpctx, sig), |
| 92 | fmt_pubkey(tmpctx, key)); |
| 93 | } |
| 94 | |
| 95 | static struct command_result *json_createoffer(struct command *cmd, |
| 96 | const char *buffer, |
no test coverage detected