If they hand us the payer secret, we sign it directly, bypassing checks * about periods etc. */
| 1058 | /* If they hand us the payer secret, we sign it directly, bypassing checks |
| 1059 | * about periods etc. */ |
| 1060 | static struct command_result * |
| 1061 | force_payer_secret(struct command *cmd, |
| 1062 | struct sent *sent, |
| 1063 | struct tlv_invoice_request *invreq, |
| 1064 | const struct secret *payer_secret) |
| 1065 | { |
| 1066 | struct sha256 merkle, sha; |
| 1067 | enum nodeid_parity parity; |
| 1068 | secp256k1_keypair kp; |
| 1069 | u8 *msg; |
| 1070 | const u8 *p; |
| 1071 | size_t len; |
| 1072 | |
| 1073 | if (secp256k1_keypair_create(secp256k1_ctx, &kp, payer_secret->data) != 1) |
| 1074 | return command_fail(cmd, LIGHTNINGD, "Bad payer_secret"); |
| 1075 | |
| 1076 | invreq->payer_key = tal(invreq, struct point32); |
| 1077 | /* Docs say this only happens if arguments are invalid! */ |
| 1078 | if (secp256k1_keypair_xonly_pub(secp256k1_ctx, |
| 1079 | &invreq->payer_key->pubkey, NULL, |
| 1080 | &kp) != 1) |
| 1081 | plugin_err(cmd->plugin, |
| 1082 | "secp256k1_keypair_pub failed on %s?", |
| 1083 | type_to_string(tmpctx, struct secret, payer_secret)); |
| 1084 | |
| 1085 | /* Linearize populates ->fields */ |
| 1086 | msg = tal_arr(tmpctx, u8, 0); |
| 1087 | towire_tlv_invoice_request(&msg, invreq); |
| 1088 | p = msg; |
| 1089 | len = tal_bytelen(msg); |
| 1090 | sent->invreq = fromwire_tlv_invoice_request(cmd, &p, &len); |
| 1091 | if (!sent->invreq) |
| 1092 | plugin_err(cmd->plugin, |
| 1093 | "Could not remarshall invreq %s", tal_hex(tmpctx, msg)); |
| 1094 | |
| 1095 | merkle_tlv(sent->invreq->fields, &merkle); |
| 1096 | sighash_from_merkle("invoice_request", "signature", &merkle, &sha); |
| 1097 | |
| 1098 | sent->invreq->signature = tal(invreq, struct bip340sig); |
| 1099 | if (!secp256k1_schnorrsig_sign32(secp256k1_ctx, |
| 1100 | sent->invreq->signature->u8, |
| 1101 | sha.u.u8, |
| 1102 | &kp, |
| 1103 | NULL)) { |
| 1104 | return command_fail(cmd, LIGHTNINGD, |
| 1105 | "Failed to sign with payer_secret"); |
| 1106 | } |
| 1107 | |
| 1108 | sent->path = path_to_node(sent, cmd->plugin, |
| 1109 | sent->offer->node_id, |
| 1110 | &parity); |
| 1111 | if (!sent->path) |
| 1112 | return connect_direct(cmd, sent->offer->node_id, parity, |
| 1113 | sendinvreq_after_connect, sent); |
| 1114 | |
| 1115 | return sendinvreq_after_connect(cmd, NULL, NULL, sent); |
| 1116 | } |
| 1117 |
no test coverage detected